-
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 e31bf78
Showing
8 changed files
with
504 additions
and
10 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
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,31 @@ | ||
local native = require("nvim-paredit.indentation.native") | ||
local config = require("nvim-paredit.config") | ||
|
||
local M = {} | ||
|
||
function M.handle_indentation(event, opts) | ||
local auto_indent = opts.auto_indent or config.config.auto_indent | ||
if not auto_indent then | ||
return | ||
end | ||
|
||
local indent_fn = opts.indent_fn or config.config.indent_fn or native.indent | ||
if not indent_fn then | ||
return | ||
end | ||
|
||
local tree = vim.treesitter.get_parser(0) | ||
|
||
tree:parse() | ||
|
||
local parent = tree:named_node_for_range(event.parent_range) | ||
indent_fn( | ||
vim.tbl_deep_extend("force", event, { | ||
tree = tree, | ||
parent = parent, | ||
}), | ||
opts | ||
) | ||
end | ||
|
||
return M |
Oops, something went wrong.