parinfer

cfleming 2017-08-18T02:21:17.000014Z

Here’s a WIP of what this looks like in Cursive now.

cfleming 2017-08-18T02:21:29.000177Z

It never runs paren mode automatically, because of: https://github.com/shaunlebron/parinfer/wiki/Problems-integrating-parinfer-into-Cursive

cfleming 2017-08-18T02:22:12.000152Z

I made some trivial modifications to paren mode, so that it now returns where in the doc the indentation is incorrect, and I can now mark this in the editor:

cfleming 2017-08-18T02:22:57.000024Z

The markers get a tooltip explaining what’s going on:

cfleming 2017-08-18T02:24:09.000111Z

If the user modifies the document, they’ll be notified that parinfer cannot be applied:

cfleming 2017-08-18T02:24:59.000091Z

I don’t notify on caret movement even though parinfer can’t be applied then either, it’s a little intrusive.

cfleming 2017-08-18T02:25:34.000152Z

It’s possible this is stockholm syndrome since I can’t do anything else, but I actually like this better than automatically running paren mode.

cfleming 2017-08-18T02:26:11.000016Z

Here’s what I’m planning to do to improve this.

cfleming 2017-08-18T02:27:16.000177Z

The paren mode indentation check can also be trivially made to return the extents of all the top-level forms in the document, and also to record whether each top-level form is correctly indented or not.

cfleming 2017-08-18T02:27:46.000020Z

After these recent changes, parinfer is only run in response to a change or caret movement.

cfleming 2017-08-18T02:29:24.000078Z

So when I come to run it, I will have: 1. a list of changes and where in the doc they happened, 2. a list of top-level forms and whether they’re correctly indented or not.

cfleming 2017-08-18T02:30:06.000135Z

I can then run parinfer just over the top-level forms which are correctly indented, and which intersect with a change (i.e. the user made a modification within that form).

cfleming 2017-08-18T02:31:01.000005Z

If any of the changes intersect top-level forms which cannot have parinfer run over them because their indentation is inconsistent, the user will get an error as above and parinfer will not run.

cfleming 2017-08-18T02:31:46.000031Z

It’s an open question whether I should run partially, i.e. process the top-level forms which are correctly indented even if some are not - I’ll need to try that.

cfleming 2017-08-18T02:32:06.000134Z

This has some really nice properties:

cfleming 2017-08-18T02:32:33.000097Z

1. Files are never modified just by looking at them, which is disturbing for many users (and me).

cfleming 2017-08-18T02:33:36.000122Z

2. Parinfer will only be applied locally, so it will only make changes in the region of the file the user is modifying, and only when the user actually makes changes and is presumably looking to see what happened.

cfleming 2017-08-18T02:34:31.000123Z

3. Even if a file is inconsistently indented, as long as the section of the file the user wants to work on is consistent, there’s no problem. The other section of the file will not be touched, and parinfer will work where the user is working.

cfleming 2017-08-18T02:35:07.000163Z

4. There’s no need for parlinter or anything similar, which should make adoption in mixed teams much easier.

cfleming 2017-08-18T02:36:20.000110Z

There are a few details to work out, but I think this is a really nice model.

cfleming 2017-08-18T02:40:26.000008Z

The integration is somewhat IntelliJ specific, but I think this should be relatively easy to integrate into any editor which supports markers like the above in the editor.

cfleming 2017-08-18T02:42:28.000161Z

One more screenshot - if the line is incorrectly dedented and there’s no whitespace at the line start, the first char is marked:

shaunlebron 2017-08-18T11:32:29.000198Z

@cfleming: wow, this is great!

shaunlebron 2017-08-18T15:48:31.000066Z

will you mark other things that paren mode corrects? paren trails

cfleming 2017-08-18T18:54:38.000138Z

No, the important thing I want to communicate to the user is what they need to fix to get the doc into a valid state.

cfleming 2017-08-18T18:54:44.000193Z

That’s only indentation, really.

cfleming 2017-08-18T18:54:58.000471Z

Then they can fix it by hand, or reformat the doc, or whatever.

shaunlebron 2017-08-18T18:59:39.000402Z

so close-parens at the start of a line will be moved when a file is opened, as long as the indentation is fine?

cfleming 2017-08-18T19:05:27.000362Z

No, but close parens at the start of a line wouldn’t prevent parinfer from running, right? They’ll just get tidied up when it does.

cfleming 2017-08-18T19:06:21.000196Z

I guess that will cause paren mode to run, so I could detect that case in order to just go ahead and run paren mode rather than smart mode, but it’s not something the user should have to think about.

shaunlebron 2017-08-18T20:42:24.000099Z

I’m not sure what “prevent parinfer from running” means

shaunlebron 2017-08-18T20:45:27.000408Z

incorrect indentation doesn’t prevent parinfer from running, so if you mean “cause parinfer to perform structural changes”, then I suppose it’s okay to ignore paren movement

shaunlebron 2017-08-18T20:45:54.000036Z

but this does violate your first property “1. Files are never modified just by looking at them”

cfleming 2017-08-18T22:51:31.000020Z

You’re right that it doesn’t prevent parinfer from running, but it does prevent me from running it without breaking people’s code which is the problem I’m actually trying to solve.

cfleming 2017-08-18T22:52:37.000078Z

I’m not sure I understand - why would that violate the first property? That just says that a file will never be modified simply by opening it, which is very surprising to users right now.