parinfer

shaunlebron 2017-08-19T00:40:50.000025Z

I misunderstood—you’re only applying the markers after a user modifies the document

shaunlebron 2017-08-19T00:42:04.000071Z

and this solves your problem because you are now running paren mode after every edit? actually I’m still unsure how this solves your problem

shaunlebron 2017-08-19T00:51:39.000029Z

Your new steps as I understand them: 1. On file open, parinfer is not used to do any processing. 2. On file edit, parinfer is only applied if indentation was correct prior to the edit. otherwise, mark the offending lines.

shaunlebron 2017-08-19T00:52:42.000028Z

step 2 seems to contradict this section, saying it’s impossible: https://github.com/shaunlebron/parinfer/wiki/Problems-integrating-parinfer-into-Cursive#run-paren-mode-before-editor-action

cfleming 2017-08-19T02:31:41.000044Z

So the thing that makes all this possible that I only just figured out this week is that in a document modification listener I can’t modify the document contents, but I can add markers.

cfleming 2017-08-19T02:33:24.000008Z

So briefly, the flow is this:

cfleming 2017-08-19T02:33:40.000036Z

1. On file open, no processing is performed, correct.

cfleming 2017-08-19T02:34:54.000049Z

2. The “bad indentation” markers are calculated and applied in an inspection, which runs on the background all the time. So they will always be visible when the user is in paredit mode, they’re not dependent on any particular stage of this process.

cfleming 2017-08-19T02:36:21.000059Z

3. On first document edit, before the edit is applied I run my paren mode indentation check and record the results. I apply markers to the document corresponding to the edit, and record what the indent delta for that particular edit is.

cfleming 2017-08-19T02:37:40.000023Z

4. When the series of edits (IntelliJ calls this a Command, basically an undoable group of edits) finishes, I check the indentation results from step 3. If the indentation was correct before the command started then I apply parinfer, otherwise I show the warning. The changes to pass to parinfer are calculated from the markers from step 2.

cfleming 2017-08-19T02:38:33.000055Z

I have this all working now, and although I’ve only done rudimentary testing so far it seems to work fine.

cfleming 2017-08-19T02:41:49.000011Z

This also happens based on caret movement, which works in a similar way.

cfleming 2017-08-19T05:56:02.000029Z

So next week I’m going to try the top-level form improvement, and I also have to see if I can modify parinfer to handle multiple caret positions in a sensible way.

cfleming 2017-08-19T05:57:11.000043Z

Basically, for each editor viewing a particular document, I’ll have a prevCursor and cursor position.

cfleming 2017-08-19T05:58:44.000046Z

Once I have a working WIP I’ll put it somewhere so interested people can try it out.

cfleming 2017-08-19T08:00:00.000081Z

Is it a true statement that caret movement can only affect how parinfer indents code/retains parens at the point the caret is moving from?

cfleming 2017-08-19T08:00:34.000098Z

i.e. if I move the caret from some point in a document to another point, that will never affect the result at the destination point until the user starts editing there.

rgdelato 2017-08-19T08:42:07.000046Z

I don't know if this is what you mean, but

(foo
  |)
will become
(foo|)
if you move your caret to the top line

cfleming 2017-08-19T09:45:03.000076Z

Right, but that’s caused by the caret leaving line 2. So if you e.g. clicked in a totally different form, only the form the caret is leaving will be affected.

shaunlebron 2017-08-19T15:17:44.000072Z

parinfer will suspend certain operations around forms that the cursor is touching

shaunlebron 2017-08-19T15:18:06.000086Z

when the cursor leaves, the form is released

shaunlebron 2017-08-19T15:21:10.000026Z

when the cursor enters a new form, the form is probably already normalized, so there are really no rules to suspend until something is edited

shaunlebron 2017-08-19T15:21:37.000097Z

so I think it’s safe to assume your stated property is correct (i.e. cursor entering a new form will not modify it)

Aron 2017-08-19T20:16:10.000087Z

anyone using neovim/linux?

dominicm 2017-08-19T21:59:40.000071Z

Yep!