I misunderstood—you’re only applying the markers after a user modifies the document
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
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.
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
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.
So briefly, the flow is this:
1. On file open, no processing is performed, correct.
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.
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.
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.
I have this all working now, and although I’ve only done rudimentary testing so far it seems to work fine.
This also happens based on caret movement, which works in a similar way.
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.
Basically, for each editor viewing a particular document, I’ll have a prevCursor and cursor position.
Once I have a working WIP I’ll put it somewhere so interested people can try it out.
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?
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.
I don't know if this is what you mean, but
(foo
|)
will become
(foo|)
if you move your caret to the top lineRight, 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.
parinfer will suspend certain operations around forms that the cursor is touching
when the cursor leaves, the form is released
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
so I think it’s safe to assume your stated property is correct (i.e. cursor entering a new form will not modify it)
anyone using neovim/linux?
Yep!