Fork me on GitHub
#parinfer
<
2017-08-18
>
cfleming02:08:17

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

cfleming02:08:12

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:

cfleming02:08:57

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

cfleming02:08:09

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

cfleming02:08:59

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

cfleming02:08:34

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.

cfleming02:08:11

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

cfleming02:08:16

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.

cfleming02:08:46

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

cfleming02:08:24

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.

cfleming02:08:06

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

cfleming02:08:01

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.

cfleming02:08:46

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.

cfleming02:08:06

This has some really nice properties:

cfleming02:08:33

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

cfleming02:08:36

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.

cfleming02:08:31

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.

cfleming02:08:07

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

cfleming02:08:20

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

cfleming02:08:26

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.

cfleming02:08:28

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

shaunlebron11:08:29

@cfleming: wow, this is great!

shaunlebron15:08:31

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

cfleming18:08:38

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.

cfleming18:08:44

That’s only indentation, really.

cfleming18:08:58

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

shaunlebron18:08:39

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

cfleming19:08:27

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.

cfleming19:08:21

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.

shaunlebron20:08:24

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

shaunlebron20:08:27

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

shaunlebron20:08:54

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

cfleming22:08:31

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.

cfleming22:08:37

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.