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

How to make multi-line maps #183

Closed skylize closed 6 years ago

skylize commented 6 years ago

Just trying to go through the ClosureScript Quick Start and already running into problems here.

Expected:

(require 'cljs.build.api)

(cljs.build.api/build "src"
  {:main 'hello-world.core
  :output-to "out/main.js"})

Actual:

(require 'cljs.build.api)

(cljs.build.api/build "src"
  {:main 'hello-world.core}
  :output-to "out/main.js")

No matter what I try, parinfer will not seem to allow a newline after 'hello-world.core. It always forces the closing } to be on the same line as the opening {. Even if I go all the way to the end after "out/main.js" to input the closing brace manually, it gets moved back to the previous line before it can even render in the intended position.

Obviously this is not a huge deal for the hello world, where I can just declare the entire map on one line and keep going, but what if I really do need to define a multi-line map? Am I supposed to disable parinfer to make work?

skylize commented 6 years ago

Oh wow. I finally just stumbled on the fix here, I need just 1 more space in the next line to line up the colons, and then everything else moves to where it belongs. 🤦‍♂️

(cljs.build.api/build "src"
  {:main 'hello-world.core
   :output-to "out/main.js"})
shaunlebron commented 6 years ago

@skylize thanks for reporting! btw, this is not your fault—communicating the rules clearly is something I'm trying to do better.

One thing I'm exploring is to show vertical lines below the open-parens. Hopefully this communicates that everything to the right of this line is inside its structure.

before:

screen shot 2018-01-30 at 10 25 34 am

after:

screen shot 2018-01-30 at 10 25 43 am

You can try this in the demo editor right now, but I will be trying to integrate it in the other editors since it is an important part of the visual language.

skylize commented 6 years ago

Thanks for the reply.

That sounds promising as a bit of extra communication, but you should probably make it optional. Some people will find all those lines everywhere very annoying.

Personally I would prefer if Enter would try to honor the characters that follow the cursor when it makes sense and move them to the following line with the cursor in the accordingly correct position. Though obviously many others might find it less convenient than the current setup where they almost never need to type closing parens.

In my example here, | is representing the cursor.

(cljs.build.api/build "src"
  {:main 'hello-world.core|})

Pressing Enter would do this.

(cljs.build.api/build "src"
  {:main 'hello-world.core
   |})

You could still collapse whitespace that has only parens-like characters after it.

(cljs.build.api/build "src"
  {:main 'hello-world.core
   })|

Pressing Enter would do this.

(cljs.build.api/build "src"
  {:main 'hello-world.core})
  |

Maybe this is outside the scope of what this editor-agnostic package can do? But if it's feasable, it seems preferable to me, allowing more control over expressing intentions up front.