Allowing passing of ranges directly to formatting tools#188
Allowing passing of ranges directly to formatting tools#188bzvl wants to merge 2 commits intosbdchd:masterfrom
Conversation
|
Is there any interest in this feature? I've been using it locally and it's been really helpful for partially formatted files. |
autoload/neoformat.vim
Outdated
| let stdin = getbufline(bufnr('%'), 1, '$') | ||
| else | ||
| let lines_after = getbufline(bufnr('%'), a:end_line + 1, '$') | ||
| let lines_before = getbufline(bufnr('%'), 1, a:start_line - 1) |
There was a problem hiding this comment.
It seems that lines_after and lines_before
There was a problem hiding this comment.
It looks like your comment was cutoff, what about them?
There was a problem hiding this comment.
Oops. Yeah I meant to say that it seems that lines_after and lines_before aren't used
|
Yeah I think it looks pretty nice. |
|
Sure. Also, since using this, I've realized that just support_range isn't enough, because various tools work different ways. Some of them take in a range and output formatted code for just the lines that match the range. Other ones take in a range and output the entire file, with only that range formatted. So I had some local changes to handle that. I'll rebase to the latest master and push a version with these changes. And yeah, I'll update the README.md, didn't notice that, thanks. |
Neoformat supports formatting only part of a file, but it just passes that chunk to formatting tools. A lot of tools need the context of the surrounding lines, but support passing the requested range as an argument. This commit adds support for ranges by allowing certain variables to be substituted in the arguments. In that case the 'range_mode' option should be to indicate that the tool itself will handle the range. Most tools use range_mode 1, which means that the tool takes the entire buffer and a range as input, and outputs the entire buffer with only that range formatted. Some tools use range_mode 2, which means that the tool takes same input as range_mode 1, but outputs only the range that was formatted.
|
A few changes here:
A handful of supported formatters support ranges. But it'll take a bit to add them and test them, so I'll do that separately. Also, I'm not sure I want to install EVERY formatter to test them :) |
|
It looks like visual_selection_before.txt is failing, because that test uses yapf and prettier, the two tools I changed to use range mode. But that test verifies that you can select different file types within a file when you use ranges, which isn't true when the entire file is passed to the formatters. I guess I'll try to use two other languages. But I'll worry about that tomorrow. |
Neoformat supports formatting only part of a file, but it just passes
that chunk to formatting tools. A lot of tools need the context of the
surrounding lines, but support passing the requested range as an
argument.
This commit adds support for ranges by allowing certain variables to be
substituted in the arguments. In that case the 'range' option should be
set to '1' to indicate that the tool itself will handle the range.