Newbie question. I’m trying to implement an “Infer parens” command in vscode. Is there a way I can take the result from parinfer.inderntMode()
and construct the “most surgical” changes I need to apply to the document? I. e. not replacing all text with the new text.
I’m looking at the Paren Trails (and the documentation for it), but it doesn’t click (to say the least).
@pez I've done this for both Vim and Kakoune. For Vim, I found it's "good enough" for performance to take the before and after text, split into lines, find the first and last changed line and replace those. For Kakoune, I used a full diffing algorithm.
Vim here: https://github.com/eraserhd/parinfer-rust/blob/master/plugin/parinfer.vim#L155
Kakoune here: https://github.com/eraserhd/parinfer-rust/blob/master/src/kakoune.rs
One nice property of parinfer is that it never changes the number of lines, which makes for a simple way of checking whether a line has changed.
@eraserhd, nice! I think replacing only the changed lines should be surgical enough for vscode as well. Will try this.
So, since you have thought of this some, @eraserhd. I’ve sort of concluded that there is no way I an figure out from the cursor position some minimal range of text to feed to intendMode()
. Is that correct, or have you figured something out?
I've seen it done in the Vimscript port of parinfer; however, it messes up on some files.
Namely, when there's a multi-line string that is dedented all the way into column 1.
It basically looks for the preceding line which starts in column 1, I think.
I won’t go there, then. Until someone actually has a problem with me using all the text. Parinfer is amazingly fast even on pretty large files.
For fomatting/indenting have so far been able to use paredit.js
to find a small enclosing range and just format that. And since cljfmt
(which I am currently using for formatting) is not blazingly fast, that is necessary.