Last active
March 18, 2024 14:18
-
-
Save mikeslattery/1c116c8fb8e812c7b0f70558194db4e1 to your computer and use it in GitHub Desktop.
which_key.nvim extension to limit how many marks are shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local M = {} | |
-- | |
-- $HOME/.config/nvim/lua/which-key/plugins/briefmarks.lua | |
-- | |
-- This extends which-key/plugins/marks.lua with these changes: | |
-- | |
-- * Only show subset of marks | |
-- * Letters | |
-- * ^ . quote | |
-- * Do not show duplicate marks | |
-- | |
-- Configuration: | |
-- | |
-- require("which-key").setup { | |
-- plugins = { | |
-- briefmarks = true, | |
-- marks = false, | |
-- ... | |
local marks_module = require('which-key.plugins.marks') | |
M.name = "briefmarks" | |
M.actions = marks_module.actions | |
function M.setup(_wk, _config, options) end | |
M.allowed_marks = { "^", ".", "'"} | |
---@type Plugin | |
---@return PluginItem[] | |
function M.run(_trigger, _mode, buf) | |
local marks = marks_module.run(_trigger, _mode, buf) | |
local unique_values = {} | |
for i = #marks, 1, -1 do | |
local key = marks[i].key | |
local value = marks[i].value | |
if (key:match("^%a$") or vim.tbl_contains(M.allowed_marks, key)) | |
and not unique_values[value] then | |
-- mark is allowed, but don't let duplicates later | |
unique_values[value] = true | |
else | |
-- Remove non-unique marks or unsupported marks | |
table.remove(marks, i) | |
end | |
end | |
return marks | |
end | |
return M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment