From 53ca9a933ec01cda1bcb2aafd76d1b80352a7538 Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:44:40 +0100 Subject: [PATCH] refactor(config)!: `useDefaultKeymaps` -> `keymaps.useDefaults` --- README.md | 39 +++++++++++++++++++++------------ lua/various-textobjs/config.lua | 30 +++++++++++++++++-------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 30090b9..beb1cfe 100644 --- a/README.md +++ b/README.md @@ -79,14 +79,22 @@ table above for you. { "chrisgrieser/nvim-various-textobjs", event = "VeryLazy", - opts = { useDefaultKeymaps = true }, + opts = { + keymaps = { + useDefaults = true + } + }, }, -- packer use { "chrisgrieser/nvim-various-textobjs", config = function () - require("various-textobjs").setup({ useDefaultKeymaps = true }) + require("various-textobjs").setup({ + keymaps = { + useDefaults = true + } + }) end, } ``` @@ -108,25 +116,28 @@ use { "chrisgrieser/nvim-various-textobjs" } ``` > [!TIP] -> You can also use the `disabledKeymaps` config option to disable only *some* -> default keymaps. +> You can also use the `keymaps.disabledDefaults` config option to disable +> only *some* default keymaps. ## Configuration ### Options -The `.setup()` call is optional if you are fine with the defaults below. +The `.setup()` call is optional if you do not want to use the default keymaps. ```lua -- default config require("various-textobjs").setup { - -- See overview table in README for the defaults keymaps. - -- (Note that lazy-loading this plugin, the default keymaps cannot be set up. - -- if you set this to `true`, you thus need to add `lazy = false` to your - -- lazy.nvim config.) - useDefaultKeymaps = false, - - ---@type string[] - disabledKeymaps = {}, -- disable only some default keymaps, e.g. { "ai", "ii" } + keymaps = { + -- See overview table in README for the defaults. (Note that lazy-loading + -- this plugin, the default keymaps cannot be set up. if you set this to + -- `true`, you thus need to add `lazy = false` to your lazy.nvim config.) + useDefaults = false, + + -- disable only some default keymaps, for example { "ai", "!" } + -- (only relevant when you set `useDefaults = true`) + ---@type string[] + disabledDefaults = {}, + }, -- Number of lines to seek forwards for a text object. See the overview table -- in the README for which text object uses which value. @@ -179,7 +190,7 @@ vim.keymap.set({ "o", "x" }, "is", 'lua require("various-textobjs").subword ``` For most text objects, there is only one parameter which accepts `"inner"` or -`"outer"`. There only exceptions is the indentation text object: +`"outer"`. There only exceptions is the `indentation` text object: ```lua -- THE INDENTATION TEXTOBJ requires two parameters, the first for diff --git a/lua/various-textobjs/config.lua b/lua/various-textobjs/config.lua index 7e191da..df6d27e 100644 --- a/lua/various-textobjs/config.lua +++ b/lua/various-textobjs/config.lua @@ -2,14 +2,17 @@ local M = {} -------------------------------------------------------------------------------- ---@class VariousTextobjs.Config local defaultConfig = { - -- See overview table in README for the defaults keymaps. - -- (Note that lazy-loading this plugin, the default keymaps cannot be set up. - -- if you set this to `true`, you thus need to add `lazy = false` to your - -- lazy.nvim config.) - useDefaultKeymaps = false, + keymaps = { + -- See overview table in README for the defaults. (Note that lazy-loading + -- this plugin, the default keymaps cannot be set up. if you set this to + -- `true`, you thus need to add `lazy = false` to your lazy.nvim config.) + useDefaults = false, - ---@type string[] - disabledKeymaps = {}, -- disable only some default keymaps, e.g. { "ai", "ii" } + -- disable only some default keymaps, for example { "ai", "!" } + -- (only relevant when you set `useDefaults = true`) + ---@type string[] + disabledDefaults = {}, + }, -- Number of lines to seek forwards for a text object. See the overview table -- in the README for which text object uses which value. @@ -76,10 +79,19 @@ function M.setup(userConfig) "The `notifyNotFound` option is deprecated. Use `notify.whenObjectNotFound` instead." ) end + -- DEPRECATION (2024-12-06) + if M.config.useDefaultKeymaps then + warn("The `useDefaultKeymaps` option is deprecated. Use `keymaps.useDefaults` instead.") + M.config.keymaps.useDefaults = M.config.useDefaultKeymaps + end + if M.config.disabledKeymaps then + warn("The `disabledKeymaps` option is deprecated. Use `keymaps.disabledDefaults` instead.") + M.config.keymaps.disabledDefaults = M.config.disabledKeymaps + end ---@diagnostic enable: undefined-field - if M.config.useDefaultKeymaps then - require("various-textobjs.default-keymaps").setup(M.config.disabledKeymaps) + if M.config.keymaps.useDefaults then + require("various-textobjs.default-keymaps").setup(M.config.keymaps.disabledDefaults) end end