-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto indentation correction on slurp/barf
This adds support for automatic indentation correction when slurping and barfing. The goal of this implementation is to: 1) Provide a visual aid to the user that allows them to confirm they are operating on the correct node, and to know when to stop when performing recursive slurp/barf operations. 2) Be simple to maintain and understand while being as correct as possible 3) Be replaceable with other implementations. 4) Be as performant as possible. There should be no lag or visual jitter The goal is _not_ to be 100% correct. If a more correct implementation is needed then one can be provided through `indent_fn`. For example, an implementation using `vim.lsp.buf.format` could be built if the user doesn't mind sacrificing performance for correctness.
- Loading branch information
1 parent
b03534c
commit 0dc4262
Showing
11 changed files
with
501 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
local common = require("nvim-paredit.utils.common") | ||
|
||
local M = {} | ||
|
||
M.config = {} | ||
|
||
function M.update_config(config) | ||
M.config = common.merge(M.config, config) | ||
M.config = vim.tbl_deep_extend("force", M.config, config) | ||
end | ||
|
||
return M |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local config = require("nvim-paredit.config") | ||
|
||
local M = {} | ||
|
||
function M.handle_indentation(event, opts) | ||
local indent = opts.indent or config.config.indent or {} | ||
if not indent.enabled or not indent.indentor then | ||
return | ||
end | ||
|
||
local tree = vim.treesitter.get_parser(0) | ||
|
||
tree:parse() | ||
local parent = tree:named_node_for_range(event.parent_range) | ||
|
||
indent.indentor( | ||
vim.tbl_deep_extend("force", event, { | ||
tree = tree, | ||
parent = parent, | ||
}), | ||
vim.tbl_deep_extend("force", opts, { | ||
indent = indent, | ||
}) | ||
) | ||
end | ||
|
||
return M |
Oops, something went wrong.