Fork me on GitHub
#parinfer
<
2018-11-21
>
pez14:11:46

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.

pez14:11:03

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

eraserhd15:11:41

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

eraserhd15:11:14

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.

pez15:11:21

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

pez15:11:25

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?

eraserhd15:11:25

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

eraserhd15:11:46

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

eraserhd15:11:06

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

pez15:11:31

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.

pez15:11:17

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.