Compare commits

..

8 commits

Author SHA1 Message Date
d99c908ac3
qutebrowser: Use fastside for redirects by default
Default to fastside.link instead of farside.link.
2024-06-27 17:36:06 +02:00
52c0260d6d
script: Close pass repository when locking screen
Before locking emit `pass close` if pass binary is found in path.
2024-06-27 17:34:42 +02:00
444c378d89
nvim: Update ZK mappings 2024-06-27 17:26:02 +02:00
851bf58b21
nvim: Improve snippet jumping
Snippets can be jumped through more easily now since jumping between
snippets (with <tab> and <s-tab>) 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 <tab> from somewhere else in the file.
2024-06-27 17:24:29 +02:00
894b7ff175
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.
2024-06-27 17:22:03 +02:00
e6497a2241
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`).
2024-06-27 17:20:35 +02:00
9ded34f73c
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.
2024-06-27 17:18:34 +02:00
7ff62840b7
nvim: Move core.autocmds to core.commands 2024-06-27 16:57:24 +02:00
9 changed files with 125 additions and 70 deletions

View file

@ -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",
})

View file

@ -0,0 +1,43 @@
-- 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",
})
-- 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 })

View file

@ -1,7 +1,7 @@
for _, source in ipairs({ for _, source in ipairs({
"core.settings", "core.settings",
"core.lazy", "core.lazy",
"core.autocmds", "core.commands",
"core.mappings", "core.mappings",
}) do }) do
local status_ok, fault = pcall(require, source) local status_ok, fault = pcall(require, source)

View file

@ -127,10 +127,11 @@ map("n", "<localleader>Q", "vapJgqap", { silent = true, desc = "Unformat then fo
-- SPELL CHECKING -- SPELL CHECKING
-- Move to the prev/next spelling error with [S ]S -- Move to the prev/next spelling error with [S ]S
-- Move to the prev/next spelling error or suggestion with [s ]s -- Move to the prev/next spelling error or suggestion with [s ]s
map("n", "<localleader>ZZ", ":setlocal spell! spelllang=en_us,en_gb,de_de<cr>", { desc = "Toggle spellcheck" }) map("n", "<localleader>ZZ", "<cmd>SpellToggle en_us en_gb de_de<cr>", { desc = "Toggle spellcheck" })
map("n", "<localleader>ZE", ":setlocal spell! spelllang=en_us<cr>", { desc = "Toggle EN_US spellcheck" }) map("n", "<localleader>ZA", "<cmd>SpellToggle! en_us en_gb de_de<cr>", { desc = "Enable spellcheck" })
map("n", "<localleader>ZB", ":setlocal spell! spelllang=en_gb<cr>", { desc = "Toggle EN_GB spellcheck" }) map("n", "<localleader>ZE", "<cmd>SpellToggle en_us<cr>", { desc = "Toggle EN_US spellcheck" })
map("n", "<localleader>ZD", ":setlocal spell! spelllang=de_de<cr>", { desc = "Toggle DE_DE spellcheck" }) map("n", "<localleader>ZB", "<cmd>SpellToggle en_gb<cr>", { desc = "Toggle EN_GB spellcheck" })
map("n", "<localleader>ZD", "<cmd>SpellToggle de_de<cr>", { desc = "Toggle DE_DE spellcheck" })
-- undo last spelling mistake from insert and normal mode -- undo last spelling mistake from insert and normal mode
map("i", "<c-z>", "<C-G>u<Esc>e[s1z=`]a<C-G>u") map("i", "<c-z>", "<C-G>u<Esc>e[s1z=`]a<C-G>u")
map("n", "<localleader>z", "mse[s1z=`s", { desc = "Fix last spell error" }) map("n", "<localleader>z", "mse[s1z=`s", { desc = "Fix last spell error" })

View file

@ -135,12 +135,12 @@ return {
}), -- disable selection in cmd mode }), -- disable selection in cmd mode
}), }),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then -- expand_or_jumpable() will always jump
cmp.select_next_item() -- expand_or_locally_jumpable() only jumps when still inside snippet region
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() if luasnip.expand_or_locally_jumpable() then
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
elseif cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then elseif has_words_before() then
cmp.complete() cmp.complete()
else else
@ -148,10 +148,10 @@ return {
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if luasnip.jumpable(-1) then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
elseif cmp.visible() then
cmp.select_prev_item()
else else
fallback() fallback()
end end

View file

@ -20,7 +20,7 @@ local servers = {
eslint = {}, eslint = {},
gopls = {}, gopls = {},
julials = {}, julials = {},
ltex = {}, ltex = { autostart = false },
lua_ls = { lua_ls = {
settings = { settings = {
Lua = { Lua = {
@ -35,9 +35,7 @@ local servers = {
}, },
}, },
}, },
marksman = { marksman = {},
filetypes = { "markdown", "quarto" },
},
basedpyright = {}, basedpyright = {},
ruff = {}, ruff = {},
serve_d = {}, serve_d = {},
@ -157,6 +155,25 @@ lsp.setup({
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
lspconfig.nushell.setup({}) 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 local python_path
-- ensure python virtualenv is determined automatically on lsp start -- ensure python virtualenv is determined automatically on lsp start
lspconfig.basedpyright.setup({ lspconfig.basedpyright.setup({
@ -201,3 +218,23 @@ if require("core.util").is_available("arduino") then
on_new_config = require("arduino").on_new_config, on_new_config = require("arduino").on_new_config,
}) })
end 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,
})

View file

@ -133,7 +133,10 @@ local prose_plugs = {
keys = { keys = {
-- additional key instpirations https://github.com/al1-ce/MonolithVim/blob/master/after/ftplugin/markdown.lua -- additional key instpirations https://github.com/al1-ce/MonolithVim/blob/master/after/ftplugin/markdown.lua
{ "<leader>ni", "<cmd>edit ~/documents/notes/index.md<cr>", desc = "open index", silent = true }, { "<leader>ni", "<cmd>edit ~/documents/notes/index.md<cr>", desc = "open index", silent = true },
{ "<leader>nn", "<cmd>ZkNotes { sort = { 'modified' } }<cr>", desc = "note list" }, { "<leader>nn", "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", desc = "new note" },
{ "<leader>nn", ":'<,'>ZkNewFromTitleSelection<cr>", desc = "new note from selection", mode = "v" },
{ "<leader>nN", ":'<,'>ZkNewFromContentSelection<cr>", desc = "content from selection", mode = "v" },
{ "<leader>nl", "<cmd>ZkNotes { sort = { 'modified' } }<cr>", desc = "note list" },
{ {
"<leader>nf", "<leader>nf",
"<Cmd>ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }<CR>", "<Cmd>ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }<CR>",
@ -142,12 +145,9 @@ local prose_plugs = {
{ "<leader>nf", "<cmd>ZkMatch<cr>", desc = "find note from selection", mode = "v" }, { "<leader>nf", "<cmd>ZkMatch<cr>", desc = "find note from selection", mode = "v" },
{ "<leader>nt", "<cmd>ZkTags<cr>", desc = "note tags" }, { "<leader>nt", "<cmd>ZkTags<cr>", desc = "note tags" },
{ "<leader>nc", "<cmd>ZkCd<cr>", desc = "notedir cd" }, { "<leader>nc", "<cmd>ZkCd<cr>", desc = "notedir cd" },
{ "<leader>no", "<cmd>ZkNotes { sort = { 'modified' } }<cr>", desc = "orphans list" }, { "<leader>no", "<cmd>ZkOrphans { sort = { 'modified' } }<cr>", desc = "orphans list" },
{ "<leader>nl", "<cmd>ZkLinks<cr>", desc = "note links" }, { "<localleader>nb", "<cmd>ZkBacklinks<cr>", desc = "note backlinks" },
{ "<leader>nb", "<cmd>ZkBacklinks<cr>", desc = "note backlinks" }, { "<localleader>nl", "<cmd>ZkLinks<cr>", desc = "note links" },
{ "<localleader>nn", "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", desc = "new note" },
{ "<localleader>nn", ":'<,'>ZkNewFromTitleSelection<cr>", desc = "new note from selection", mode = "v" },
{ "<localleader>nN", ":'<,'>ZkNewFromContentSelection<cr>", desc = "content from selection", mode = "v" },
}, },
}, },
@ -182,8 +182,6 @@ local prose_plugs = {
{ {
"barreiroleo/ltex_extra.nvim", "barreiroleo/ltex_extra.nvim",
branch = "dev", branch = "dev",
ft = writing_ft,
opts = {},
}, },
} }

View file

@ -1,6 +1,6 @@
import random import random
import re import re
from typing import Any, Callable from typing import Callable
from urllib import parse from urllib import parse
from qutebrowser.api import interceptor from qutebrowser.api import interceptor
@ -29,7 +29,11 @@ def fixScribePath(url: QUrl):
return url return url
redirects = { type Service = dict[str, list[str]]
type Redirects = dict[str, Service]
redirects: Redirects = {
"youtube": { "youtube": {
"source": ["youtube.com"], "source": ["youtube.com"],
"farside": ["invidious"], "farside": ["invidious"],
@ -163,11 +167,9 @@ def rewrite(request: interceptor.Request) -> None:
url = request.request_url url = request.request_url
if service := _should_be_redirected(url.host()): if service := _should_be_redirected(url.host()):
if "farside" in service: url = _farside_redirect(
url = _farside_redirect(url, _pick_random(service["farside"])) url, _pick_random(service["farside" if "farside" in service else "target"])
else: )
srv = _pick_random(service["target"])
url = _target_redirect(url, srv)
try: try:
request.redirect(url) request.redirect(url)
except RedirectException as e: except RedirectException as e:
@ -177,28 +179,24 @@ def rewrite(request: interceptor.Request) -> None:
url = service["postprocess"](url) 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: try:
url.setHost("farside.link") url.setHost("fastside.link" if use_fastside else "farside.link")
url.setPath(f"/{service}{url.path()}") url.setPath(f"/{service}{url.path()}")
except RedirectException as e: except RedirectException as e:
message.error(str(e)) message.error(str(e))
return url return url
def _target_redirect(url: QUrl, target: str) -> QUrl: def _pick_random[T](choices: list[T]) -> T:
if target is not None and url.setHost(target) is not False:
return url
return url
def _pick_random(choices: list) -> Any:
return choices[random.randint(0, len(choices) - 1)] return choices[random.randint(0, len(choices) - 1)]
def _should_be_redirected( def _should_be_redirected(
host: str, redirects: dict = redirects # TODO: Update to use typedefs/classes instead of this jumble
) -> dict[str, list] | None: host: str,
redirects: Redirects = redirects,
) -> Service | None:
for service in redirects.values(): for service in redirects.values():
for source in service["source"]: for source in service["source"]:
if re.search(source, host): if re.search(source, host):

View file

@ -25,6 +25,10 @@ pre_lock() {
type mpc >/dev/null 2>&1 && mpc -q pause type mpc >/dev/null 2>&1 && mpc -q pause
type playerctl >/dev/null 2>&1 && playerctl -s pause type playerctl >/dev/null 2>&1 && playerctl -s pause
type amixer >/dev/null 2>&1 && amixer -q set Master mute 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 return
} }