From afd0339242d68da4d19895d918cfae3ddac817e1 Mon Sep 17 00:00:00 2001 From: Mystical-C <64483945+MysticalDevil@users.noreply.github.com> Date: Sun, 29 Oct 2023 08:04:42 +0800 Subject: [PATCH] fix: Fix legendary.nvim extensions config --- lua/devil/configs/plugin/legendary.lua | 212 +++++++++++++++++-------- lua/devil/plugins/common.lua | 18 ++- 2 files changed, 158 insertions(+), 72 deletions(-) diff --git a/lua/devil/configs/plugin/legendary.lua b/lua/devil/configs/plugin/legendary.lua index 369b9eb..8e39488 100644 --- a/lua/devil/configs/plugin/legendary.lua +++ b/lua/devil/configs/plugin/legendary.lua @@ -6,78 +6,14 @@ end local opts = { keymaps = { - -- map keys to a command - { "ff", ":Telescope find_files", description = "Find files" }, - -- map keys to a function - { - "h", - function() - print("hello world!") - end, - description = "Say hello", - }, - -- Set options used during keymap creation - { "s", ":SomeCommand", description = "Non-silent keymap", opts = { silent = true } }, - -- create keymaps with different implementations per-mode - { - "c", - { n = ":LinewiseCommentToggle", x = ":'<,'>BlockwiseCommentToggle" }, - description = "Toggle comment", - }, - -- create item groups to create sub-menus in the finder - -- note that only keymaps, commands, and functions - -- can be added to item groups - { - -- groups with same itemgroup will be merged - itemgroup = "short ID", - description = "A submenu of items...", - icon = "", - keymaps = { - -- more keymaps here - }, - }, -- in-place filters, see :h legendary-tables or ./doc/table_structures/README.md - { "m", description = "Preview markdown", filters = { ft = "markdown" } }, + { "pm", description = "Preview markdown", filters = { ft = "markdown" } }, }, commands = { - -- easily create user commands - { - ":SayHello", - function() - print("hello world!") - end, - description = "Say hello as a command", - }, - { - -- groups with same itemgroup will be merged - itemgroup = "short ID", - -- don't need to copy the other group data because - -- it will be merged with the one from the keymaps table - commands = { - -- more commands here - }, - }, -- in-place filters, see :h legendary-tables or ./doc/table_structures/README.md { ":Glow", description = "Preview markdown", filters = { ft = "markdown" } }, }, - funcs = { - -- Make arbitrary Lua functions that can be executed via the item finder - { - function() - doSomeStuff() - end, - description = "Do some stuff with a Lua function!", - }, - { - -- groups with same itemgroup will be merged - itemgroup = "short ID", - -- don't need to copy the other group data because - -- it will be merged with the one from the keymaps table - funcs = { - -- more funcs here - }, - }, - }, + -- Initial augroups/autocmds to bind, can also be a function that returns the list autocmds = { -- Create autocmds and augroups -- { "BufWritePre", vim.lsp.buf.format, description = "Format on save" }, @@ -87,11 +23,111 @@ local opts = { -- -- autocmds here -- }, }, - -- load extensions + -- Initial functions to bind, can also be a function that returns the list + funcs = {}, + -- Initial item groups to bind, + -- note that item groups can also + -- be under keymaps, commands, autocmds, or funcs; + -- can also be a function that returns the list + itemgroups = {}, + -- default opts to merge with the `opts` table + -- of each individual item + default_opts = { + -- for example, { silent = true, remap = false } + keymaps = {}, + -- for example, { args = '?', bang = true } + commands = {}, + -- for example, { buf = 0, once = true } + autocmds = {}, + }, + -- Customize the prompt that appears on your vim.ui.select() handler + -- Can be a string or a function that returns a string. + select_prompt = " legendary.nvim ", + -- Character to use to separate columns in the UI + col_separator_char = "│", + -- Optionally pass a custom formatter function. This function + -- receives the item as a parameter and the mode that legendary + -- was triggered from (e.g. `function(item, mode): string[]`) + -- and must return a table of non-nil string values for display. + -- It must return the same number of values for each item to work correctly. + -- The values will be used as column values when formatted. + -- See function `default_format(item)` in + -- `lua/legendary/ui/format.lua` to see default implementation. + default_item_formatter = nil, + -- Customize icons used by the default item formatter + icons = { + -- keymap items list the modes in which the keymap applies + -- by default, you can show an icon instead by setting this to + -- a non-nil icon + keymap = nil, + command = "", + fn = "󰡱", + itemgroup = "", + }, + -- Include builtins by default, set to false to disable + include_builtin = true, + -- Include the commands that legendary.nvim creates itself + -- in the legend by default, set to false to disable + include_legendary_cmds = true, + -- Options for list sorting. Note that fuzzy-finders will still + -- do their own sorting. For telescope.nvim, you can set it to use + -- `require('telescope.sorters').fuzzy_with_index_bias({})` when + -- triggered via `legendary.nvim`. Example config for `dressing.nvim`: + -- + -- require('dressing').setup({ + -- select = { + -- get_config = function(opts) + -- if opts.kind == 'legendary.nvim' then + -- return { + -- telescope = { + -- sorter = require('telescope.sorters').fuzzy_with_index_bias({}) + -- } + -- } + -- else + -- return {} + -- end + -- end + -- } + -- }) + sort = { + -- put most recently selected item first, this works + -- both within global and item group lists + most_recent_first = true, + -- sort user-defined items before built-in items + user_items_first = true, + -- sort the specified item type before other item types, + -- value must be one of: 'keymap', 'command', 'autocmd', 'group', nil + item_type_bias = nil, + -- settings for frecency sorting. + -- https://en.wikipedia.org/wiki/Frecency + -- Set `frecency = false` to disable. + -- this feature requires sqlite.lua (https://github.com/kkharji/sqlite.lua) + -- and will be automatically disabled if sqlite is not available. + -- NOTE: THIS TAKES PRECEDENCE OVER OTHER SORT OPTIONS! + frecency = { + -- the directory to store the database in + db_root = string.format("%s/legendary/", vim.fn.stdpath("data")), + -- the maximum number of timestamps for a single item + -- to store in the database + max_timestamps = 10, + }, + }, + lazy_nvim = { + -- Automatically register keymaps that are defined on lazy.nvim plugin specs + -- using the `keys = {}` property. + auto_register = false, + }, + -- Which extensions to load; no extensions are loaded by default. + -- Setting the plugin name to `false` disables loading the extension. + -- Setting it to any other value will attempt to load the extension, + -- and pass the value as an argument to the extension, which should + -- be a single function. Extensions are modules under `legendary.extensions.*` + -- which return a single function, which is responsible for loading and + -- initializing the extension. extensions = { -- load keymaps and commands from nvim-tree.lua - nvim_tree = true, - -- load commands from smart-splits.nvim + nvim_tree = false, + -- load commands from smart-splits.nvi -- and create keymaps, see :h legendary-extensions-smart-splits.nvim smart_splits = { directions = { "h", "j", "k", "l" }, @@ -101,10 +137,46 @@ local opts = { }, }, -- load commands from op.nvim - op_nvim = true, + op_nvim = false, -- load keymaps from diffview.nvim diffview = true, + -- load keymaps from which-keys.nvim + which_key = { + -- Automatically add which-key tables to legendary + -- see ./doc/WHICH_KEY.md for more details + auto_register = false, + -- you can put which-key.nvim tables here, + -- or alternatively have them auto-register, + -- see ./doc/WHICH_KEY.md + mappings = {}, + opts = {}, + -- controls whether legendary.nvim actually binds they keymaps, + -- or if you want to let which-key.nvim handle the bindings. + -- if not passed, true by default + do_binding = true, + -- controls whether to use legendary.nvim item groups + -- matching your which-key.nvim groups; if false, all keymaps + -- are added at toplevel instead of in a group. + use_groups = true, + }, + }, + scratchpad = { + -- How to open the scratchpad buffer, + -- 'current' for current window, 'float' + -- for floating window + view = "float", + -- How to show the results of evaluated Lua code. + -- 'print' for `print(result)`, 'float' for a floating window. + results_view = "float", + -- Border style for floating windows related to the scratchpad + float_border = "rounded", + -- Whether to restore scratchpad contents from a cache file + keep_contents = true, }, + -- Directory used for caches + cache_path = string.format("%s/legendary/", vim.fn.stdpath("cache")), + -- Log level, one of 'trace', 'debug', 'info', 'warn', 'error', 'fatal' + log_level = "info", } legendary.setup(opts) diff --git a/lua/devil/plugins/common.lua b/lua/devil/plugins/common.lua index 4bfa9b1..12c5426 100644 --- a/lua/devil/plugins/common.lua +++ b/lua/devil/plugins/common.lua @@ -227,11 +227,13 @@ return { "mrjones2014/legendary.nvim", priority = 10000, lazy = false, - dependencies = { "kkharji/sqlite.lua" }, + dependencies = { + "kkharji/sqlite.lua", + "mrjones2014/smart-splits.nvim", + }, config = function() require("devil.configs.plugin.legendary") end, - enabled = false, }, -- lualine.nvim -- A blazing fast and easy to configure neovim statusline plugin written in pure lua @@ -609,6 +611,18 @@ return { { "nvim-telescope/telescope-fzy-native.nvim" }, }, }, + -- smart-splits.nvim + -- Smart, seamless, directional navigation and resizing of Neovim + + -- terminal multiplexer splits. Supports tmux, Wezterm, and Kitty. + -- Think about splits in terms of "up/down/left/right". + { + "mrjones2014/smart-splits.nvim", + build = "./kitty/install-kittens.bash", + version = ">=1.0.0", + config = function() + require("devil.configs.plugin.smart-splits") + end, + }, -- sniprun -- A neovim plugin to run lines/blocs of code {