Skip to content

Commit

Permalink
refactor(config)!: useDefaultKeymaps -> keymaps.useDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 6, 2024
1 parent 95c17f4 commit 8db5583
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
```
Expand All @@ -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.
Expand Down Expand Up @@ -179,7 +190,7 @@ vim.keymap.set({ "o", "x" }, "is", '<cmd>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
Expand Down
30 changes: 21 additions & 9 deletions lua/various-textobjs/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8db5583

Please sign in to comment.