parinfer

pez 2018-11-21T14:43:46.033Z

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.

pez 2018-11-21T14:46:03.035100Z

I’m looking at the Paren Trails (and the documentation for it), but it doesn’t click (to say the least).

eraserhd 2018-11-21T15:10:41.037100Z

@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.

eraserhd 2018-11-21T15:12:34.037600Z

Kakoune here: https://github.com/eraserhd/parinfer-rust/blob/master/src/kakoune.rs

eraserhd 2018-11-21T15:13:14.038400Z

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.

pez 2018-11-21T15:18:21.040Z

@eraserhd, nice! I think replacing only the changed lines should be surgical enough for vscode as well. Will try this.

pez 2018-11-21T15:21:25.042200Z

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?

eraserhd 2018-11-21T15:22:25.043400Z

I've seen it done in the Vimscript port of parinfer; however, it messes up on some files.

eraserhd 2018-11-21T15:22:46.044Z

Namely, when there's a multi-line string that is dedented all the way into column 1.

eraserhd 2018-11-21T15:23:06.044600Z

It basically looks for the preceding line which starts in column 1, I think.

pez 2018-11-21T15:24:31.046100Z

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.

pez 2018-11-21T15:27:17.048700Z

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.