ccw-ide / ccw

Counterclockwise is an Eclipse plugin helping developers write Clojure code
https://github.com/laurentpetit/ccw/wiki/GoogleCodeHome
Eclipse Public License 1.0
220 stars 50 forks source link

Expand right first in Clojure mode #831

Open arichiardi opened 9 years ago

arichiardi commented 9 years ago

An idea for a possible feature (hijacked form expand-region.el). In Clojure, we usually have let blocks like this (where | is point):

(let [binding1 |(map f coll) binding2 :constant] ..do..)

I always want to select binding1 |(map f coll) together so that I can go to my repl and easily paste it after a def, like: (def binding1 (map f coll)), but at the second expand-region actually selects the whole content of the let.

We could probably easily implement it in CCW.

laurentpetit commented 9 years ago

Ok, so maybe I should ask questions here.

Currently, I would do, if the cursor is at the | location : expand right, expand left, expand left.

What we could do, is use expand up, and, instead of immediately selecting all the siblings inside the binding, it could select 'binding1 (map f coll)'

Is it what you're asking for?

If so, we could indeed add some logic to do that in paredit, e.g. something generic like :

2015-07-31 14:41 GMT+02:00 Andrea Richiardi notifications@github.com:

An idea for a possible feature (hijacked form expand-region.el). In Clojure, we usually have let blocks like this (where | is point):

(let [binding1 |(map f coll) binding2 :constant] ..do..)

I always want to select binding1 |(map f coll) together so that I can go to my repl and easily paste it after a def, like: (def binding1 (map f coll)), but at the second expand-region actually selects the whole content of the let.

We could probably easily implement it in CCW.

— Reply to this email directly or view it on GitHub https://github.com/laurentpetit/ccw/issues/831.

Laurent Petit

arichiardi commented 9 years ago

I am asking exactly something like that!

About the context, maybe just let and friends is appropriate as my purpose is really only the one described...that is to be able to just write () ... def in a repl and paste so that I can obtain a symbol bound to an expression.

The map literal has some corner cases. For instance when the key is a keyword.

laurentpetit commented 9 years ago

I don't understand why key being a keyword is a corner case?

2015-07-31 16:18 GMT+02:00 Andrea Richiardi notifications@github.com:

I am asking exactly something like that!

About the context, maybe just let and friends is appropriate as my purpose is really only the one described...that is to be able to just write () ... def in a repl and paste so that I can obtain a symbol bound to an expression.

The map literal has some corner cases. For instance when the key is a keyword.

— Reply to this email directly or view it on GitHub https://github.com/laurentpetit/ccw/issues/831#issuecomment-126706800.

Laurent Petit

arichiardi commented 9 years ago

Because of this:

{:key1 |4
 :key2 5}

> (def :key 4)
java.lang.RuntimeException: First argument to def must be a Symbol
arichiardi commented 9 years ago

Well you are right, if we remove the colon it would work.

laurentpetit commented 9 years ago

I didn't say it would be interesting for exactly your use case. But that it also makes sense, for maps, to have an intermediate selection level which takes the key/value pair, e.g. for copy/paste elsewhere, or deletion, etc.

2015-07-31 16:29 GMT+02:00 Andrea Richiardi notifications@github.com:

Well you are right, if we remove the colon it would work.

— Reply to this email directly or view it on GitHub https://github.com/laurentpetit/ccw/issues/831#issuecomment-126708931.

Laurent Petit

arichiardi commented 9 years ago

Yes that's useful as well!