parinfer / parinfer.js

Let's simplify the way we write Lisp
https://shaunlebron.github.io/parinfer
MIT License
1.76k stars 40 forks source link

Unmatched close-parens #102

Closed shaunlebron closed 8 years ago

shaunlebron commented 8 years ago

thanks to @snoe for bringing this up.

Currently, unmatched close-parens are removed indiscriminately. This is a problem for the following case

(foo [|bar) baz

because Indent Mode will turn it into:

(foo [|bar baz])

The obvious solution is to match the ) with the ( further back, then to close all open-parens between them, so that we have this:

(foo [|bar]) baz

But this new behavior would imply that typing an unmatched ) below

(foo [bar| baz])

would result in:

(foo [bar])| baz

I will look at how this affects Indent Mode.

shaunlebron commented 8 years ago

fixing this would break barf feature seen here:

http://shaunlebron.github.io/parinfer/#inserting-parens

shaunlebron commented 8 years ago

not sure how to fix this. I think i'll define this as a problem w/ no solution in Indent Mode.

shaunlebron commented 8 years ago

Problem statement: Inserting a ( is only safe when the next ) is inferred.

shaunlebron commented 8 years ago

This is the result of an assumption that was made without much thought:

Any unmatched close-parens are removed. This makes the next transformations simpler and more predictable.

shaunlebron commented 8 years ago

More examples of unexpected behaviors related to this issue:

shaunlebron commented 8 years ago

Proposing a new rule to cut down on surprise while preserving benefits:

Examples:

Rather than removing the unmatched close-paren here, we simply highlight what is preventing parinfer from proceeding.

(foo [|bar) baz
          ^ highlight unmatched

User then completes the operation since it cannot be inferred.

(foo [bar]) baz
shaunlebron commented 8 years ago

started work here: https://github.com/shaunlebron/parinfer/tree/unmatched-close-paren

shaunlebron commented 8 years ago

satisfied with this. in 1.9.0-beta, not released yet