-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for form indentation on slurp/barf #9
Conversation
aca3535
to
db5200f
Compare
Also added zprint support, it is a third party cli tool and it is much faster than LSP approach. To play around with it add this you your config somewhere: local function zpr(input)
-- assuming zprint binary name is "zpr" and it is available in PATH
local result = vim.fn.system("echo '" .. input .. "' | zpr '{:style [:indent-only :respect-nl]}'")
if result then
return result:gsub("\r?\n$", "")
end
return input
end
local function zprint_indent(buf, start, end_)
local api = vim.api
local lines = api.nvim_buf_get_text(buf, start[1], 0, end_[1], end_[2], {})
local text = table.concat(lines, "\n")
local result = zpr(text)
if result then
local base_indent = string.rep(" ", start[2])
local formatted_lines = {}
for line in result:gmatch("[^\r\n]+") do
table.insert(formatted_lines, base_indent .. line)
end
api.nvim_buf_set_text(buf, start[1], 0, end_[1], end_[2], formatted_lines)
end
end
and then add an option to point to indent function |
Function |
c6a8d71
to
c3447f2
Compare
my last two commits are assuming that boundary symbol only 1 char length, but it is incorrect in case of |
reverted last 4 commits, experiments failed :) |
d3ead0d
to
a652f24
Compare
a652f24
to
e31bf78
Compare
2306f0d
to
e3aa905
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super close to perfection :)
except this is not indenting:
@(foo|)
@(bar)
e3aa905
to
f40b42c
Compare
Good catch. Fixed! |
This adds support for automatic indentation correction when slurping and barfing.
The goal of this implementation is to:
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 usingvim.lsp.buf.format
could be built if the user doesn't mind sacrificing performance for correctness.