parinfer

cfleming 2017-07-18T00:06:21.803152Z

@shaunlebron Depends on the form unfortunately. I guess that will only be an issue if renaming a symbol by deleting the whole thing - it would have to get down to 1 char wide for that to be an issue.

cfleming 2017-07-18T00:07:50.822497Z

So I think I’m ok requiring some manual rearrangement in that case, since it’s likely to be far less common than other edits to leading forms - I think stickiness should be the default.

cfleming 2017-07-18T00:08:21.829391Z

Again, my initial impression without having actually used it yet - still debugging the port, and haven’t had much time this last couple of days.

tianshu 2017-07-18T00:33:55.152738Z

@shaunlebron IMO, when you want to edit some symbols, literals, etc, parens should never be changed. the indentation of bar, shouldn't affect the code struct.

rgdelato 2017-07-18T01:20:53.702670Z

I think what @shaunlebron means is if you have:

(println {:a 1
          :b 2}
   bar)
...and then you delete the println to get:
({:a 1
  :b 2}
 bar)
...what do you expect if you put the println back? This?
(println {:a 1
          :b 2}
         bar)
Or maybe this?
(println {:a 1
          :b 2}
 bar)

tianshu 2017-07-18T02:06:16.233011Z

I think both is okay, but when I have

(println {:a 1
          :b 2}
         bar)
when I change println -> print It becomes
(print {:a 1
        :b 2
        bar})

tianshu 2017-07-18T02:06:57.240766Z

it's likely a bug?

shaunlebron 2017-07-18T06:34:42.034067Z

I agree that the current behavior should be changed to prevent surprising structure changes

shaunlebron 2017-07-18T06:48:42.219481Z

thought about a minimal fix for this today. The problem happens when an open-paren moves backward. my first draft for a rule: when an open-paren moves backward, the next line should be moved backward by same amount only to prevent being newly absorbed into the list. applying this recursively for any subsequently shifted open-parens will prevent structure changes without worrying about sibling alignment, a la Paren Mode

shaunlebron 2017-07-18T06:57:52.349675Z

pushing forms around sokoban-style is as minimal a method as I can think of right now. will need more time to understand what stickiness might do and how to implement it

shaunlebron 2017-07-18T07:27:25.838210Z

a weird edge case:

(defn foo
  |[a b]
  bar
  baz)
what happens when you press backspace until [a b] is moved to previous line?

shaunlebron 2017-07-18T07:30:34.896055Z

1. with nudging:

(defn foo |[a b])
bar
  baz

shaunlebron 2017-07-18T07:32:38.935945Z

2. with stickiness:

(defn foo |[a b])
bar
baz
3. with adoption:
(defn foo |[a b
            bar
            baz])

tianshu 2017-07-18T08:24:49.002901Z

unfortunately, none of these three is what we want.

tianshu 2017-07-18T08:45:10.460162Z

I will choose 3, because when I edit indentation, usually I wish I can change the structure. If I want to achieve

(defn foo |[a b]
  bar
  baz)
I will use some command to pull this line up. but It's likely parinfer is designed for no shortcut.

shaunlebron 2017-07-18T12:59:35.812834Z

I will think about how to allow this intermediate state then:

(defn foo
|[a b]
   bar
   baz)

shaunlebron 2017-07-18T13:04:47.969903Z

we would have to use the cursor position to deduce when to prevent the close-paren from moving, like it already does in this case:

(defn foo
 [a b]|
   bar
   baz)

shaunlebron 2017-07-18T13:15:33.288673Z

structure can still change the moment you move the cursor to another line. (for example, in the original gif case—when deleting println and typing print, bar would still be absorbed by the map, unless it was indented by just two spaces)

shaunlebron 2017-07-18T13:22:07.490738Z

so, a fourth option: 4. always hold paren-trail of cursor line:

(defn foo |[a b]
  bar
  baz)

shaunlebron 2017-07-18T13:51:47.484781Z

I don’t think I can prevent structural damage in all cases, but I think I can prevent it for intermediate states—which seems most important

shaunlebron 2017-07-18T15:44:27.890913Z

we could do either of the following extra things to improve the UX around this: a) return a warning for parens that would be displaced when cursor is moved to another line—so editors can highlight them b) apply Paren Mode to prevent paren-displacement when cursor is moved to another line—can be done if we pass in previous cursor position

shaunlebron 2017-07-18T17:26:46.539923Z

made my thoughts a little more concrete here: https://github.com/shaunlebron/parinfer/issues/143#issuecomment-316125241