Closed jackfirth closed 4 days ago
Can #:ranges
be guaranteed to contain a series of well-formed expressions? If so, yes, this is totally doable!
In the case of Resyntax? Definitely.
Actually I was able to make this work entirely by using the existing #:indent
argument. To format a single [start, end)
range I did the following:
substring
start
by counting how many characters are between it and the closes preceding newline (or the start of the string)program-format
on the substring with #:indent
set to the number of leading columns from the previous stepWorked like a charm. This probably wouldn't work if fmt
supported something like file-level comments telling fmt
about custom settings, but it works well enough for my purposes.
I want to use
fmt
in Resyntax to format the refactored output code produced by Resyntax. However, Resyntax needs to avoid formatting an entire file if it only changes a few lines in the file. On the Resyntax side, I can compute a range set representing the exact character positions I want to format in the file. Canfmt
be extended to support specifying what parts of a file to format? Ideally (for me) by adding a#:ranges
keyword argument toprogram-format
that accepts arange-set?
of natural numbers representing character positions within the file.For context, Resyntax avoids touching modified lines because its suggestions are turned into GitHub pull request comments. Automated tools can't leave comments on unchanged lines in a pull request. (Or if they can, I haven't figured out how.)