Skip to content

Commit

Permalink
ref: add support for lazy plugin manager config
Browse files Browse the repository at this point in the history
  • Loading branch information
arsham committed Jan 7, 2023
1 parent f9b436a commit 523dad1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 44 deletions.
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This Neovim plugin provides mappings and textobj for indentations.
1. [Demo](#demo)
2. [Requirements](#requirements)
3. [Installation](#installation)
- [Lazy](#lazy)
- [Packer](#packer)
- [Config](#config)
- [Lazy Loading](#lazy-loading)
4. [License](#license)
Expand All @@ -25,7 +27,7 @@ Text object (`dii`, `cai`, `yii`, `vai`, etc.):
## Requirements

This library supports [Neovim
0.7.0](https://github.com/neovim/neovim/releases/tag/v0.7.0) or newer.
v0.7.0](https://github.com/neovim/neovim/releases/tag/v0.7.0) or newer.

This plugin depends are the following libraries. Please make sure to add them
as dependencies in your package manager:
Expand All @@ -34,13 +36,29 @@ as dependencies in your package manager:

## Installation

Use your favourite package manager to install this library. Packer example:
Use your favourite package manager to install this library.

### Lazy

```lua
use({
{
"arsham/indent-tools.nvim",
requires = { "arsham/arshlib.nvim" },
config = function() require("indent-tools").config({}) end,
dependencies = { "arsham/arshlib.nvim" },
config = true,
-- or to provide configuration
-- config = { normal = {..}, textobj = {..}},
}
```

### Packer

```lua
use({
"arsham/indent-tools.nvim",
requires = { "arsham/arshlib.nvim" },
config = function()
require("indent-tools").config({})
end,
})
```

Expand All @@ -53,7 +71,7 @@ To disable set them to `false`. For example:

```lua
require("indent-tools").config({
textobj = false,
textobj = false,
})
```

Expand All @@ -79,10 +97,12 @@ event is fired. Packer example:

```lua
use({
"arsham/indent-tools.nvim",
requires = { "arsham/arshlib.nvim" },
config = function() require("indent-tools").config({}) end,
keys = { "]i", "[i", { "v", "ii" }, { "o", "ii" } },
"arsham/indent-tools.nvim",
requires = { "arsham/arshlib.nvim" },
config = function()
require("indent-tools").config({})
end,
keys = { "]i", "[i", { "v", "ii" }, { "o", "ii" } },
})
```

Expand Down
2 changes: 1 addition & 1 deletion lua/indent-tools/health.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local M = {}
local health = vim.health or require("health")
local health = vim.health

M.check = function()
health.report_start("Indent Tool Health Check")
Expand Down
69 changes: 36 additions & 33 deletions lua/indent-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,44 +179,47 @@ local function setup_textobj(opts)
end
end

return {
config = function(opts) --{{{
opts = vim.tbl_deep_extend("force", defaults, opts)
vim.validate({
opts = { opts, "table" },
normal = { opts.normal, { "table", "nil", "boolean" } },
normal_up = { opts.normal.up, { "string", "nil", "boolean" } },
normal_down = { opts.normal.down, { "string", "nil", "boolean" } },
textobj = { opts.textobj, { "table", "nil", "boolean" } },
})

if opts then
if opts.normal then
if opts.normal.down then
vim.keymap.set({ "n", "x" }, opts.normal.down, function()
jump_indent(true)
end, { desc = "jump down along the indent" })
vim.keymap.set("o", opts.normal.down, function()
quick.normal("x", "V" .. opts.normal.down)
end, { desc = "jump down along the indent" })
end
local function setup(opts) --{{{
opts = vim.tbl_deep_extend("force", defaults, opts or {})
vim.validate({
opts = { opts, "table" },
normal = { opts.normal, { "table", "nil", "boolean" } },
normal_up = { opts.normal.up, { "string", "nil", "boolean" } },
normal_down = { opts.normal.down, { "string", "nil", "boolean" } },
textobj = { opts.textobj, { "table", "nil", "boolean" } },
})

if opts.normal.up then
vim.keymap.set({ "n", "x" }, opts.normal.up, function()
jump_indent(false)
end, { desc = "jump up along the indent" })
vim.keymap.set("o", opts.normal.up, function()
quick.normal("x", "V" .. opts.normal.up)
end, { desc = "jump up along the indent" })
end
if opts then
if opts.normal then
if opts.normal.down then
vim.keymap.set({ "n", "x" }, opts.normal.down, function()
jump_indent(true)
end, { desc = "jump down along the indent" })
vim.keymap.set("o", opts.normal.down, function()
quick.normal("x", "V" .. opts.normal.down)
end, { desc = "jump down along the indent" })
end

if opts.textobj then
setup_textobj(opts.textobj)
if opts.normal.up then
vim.keymap.set({ "n", "x" }, opts.normal.up, function()
jump_indent(false)
end, { desc = "jump up along the indent" })
vim.keymap.set("o", opts.normal.up, function()
quick.normal("x", "V" .. opts.normal.up)
end, { desc = "jump up along the indent" })
end
end
end,
--}}}

if opts.textobj then
setup_textobj(opts.textobj)
end
end
end
--}}}

return {
setup = setup,
config = setup,
}

-- vim: fdm=marker fdl=0

0 comments on commit 523dad1

Please sign in to comment.