How to "unwrap" an expression in CCW?

22 views
Skip to first unread message

Alex Eberts

unread,
Apr 25, 2013, 11:01:42 PM4/25/13
to clojured...@googlegroups.com
Hi All,

While writing Clojure code I often run into situations where I'd like to "unwrap" an expression (i.e. remove the inner-most parens of the statement where the cursor is). For example, let's assume we're in strict paren mode and I have the following simple function :

(map fooz [1 2 3] [:a :b :c]) 

..but I realize that I should be passing a map and not a vector to fooz as the second arg and I want to be able to remove the innermost square brackets around the keywords :a :b :c. I'm wondering if there's a CCW feature that I'm missing that will allow me to "unwrap" this expression with one keystroke.

The way I do this currently is to select the elements inside of the vector, cut the elements, erase the square brackets, type left curly brace and then copy the elements back. (6 keystrokes)

Here's how I'd like it to work (if it doesn't already exist). Let's say the cursor is between the keywords :a and :b in the following code snippet: 

(map fooz [1 2 3] [:a | :b :c])  

hitting the magical "unwrap" command would give: 

(map fooz [1 2 3] | :a  :b :c | ) 

with the keywords :a to :c selected so that I could just type "{" and I could transform the vector into a map with two keystrokes. 

Maybe I'm thinking about this in the wrong way - feedback and insights into other approaches are welcome! 
thanks,
Alex

Laurent PETIT

unread,
Apr 26, 2013, 1:50:58 AM4/26/13
to clojured...@googlegroups.com
Hello Alex,


Le vendredi 26 avril 2013, Alex Eberts a écrit :
Hi All,

While writing Clojure code I often run into situations where I'd like to "unwrap" an expression (i.e. remove the inner-most parens of the statement where the cursor is). For example, let's assume we're in strict paren mode and I have the following simple function :

(map fooz [1 2 3] [:a :b :c]) 

..but I realize that I should be passing a map and not a vector to fooz as the second arg and I want to be able to remove the innermost square brackets around the keywords :a :b :c. I'm wondering if there's a CCW feature that I'm missing that will allow me to "unwrap" this expression with one keystroke.

The way I do this currently is to select the elements inside of the vector, cut the elements, erase the square brackets, type left curly brace and then copy the elements back. (6 keystrokes)

Here's how I'd like it to work (if it doesn't already exist). Let's say the cursor is between the keywords :a and :b in the following code snippet: 

(map fooz [1 2 3] [:a | :b :c])  

You can indeed do better with ccw, but not quite what you're describing, look:

You'll first select what you want to unwrap (meaning you could just unwrap say :b :c and drop :a as well as the parens):

Hit shift+alt+UP => (map foo [1 2 3] [ | :a :b :c  | ])

See, all siblings are selected in one keystroke

Second, Raise the selection over its parent:
Hit alt+R => (map foo [1 2 3]  | :a :b :c  | )

Third, select :a :b :c if the selection is lost (it shouldn't but I don't remember right now if the regression has been fixed recently)

Then wrap the selection inside brackets by just typing the opening bracket:

Type { =>  map foo [1 2 3]  { :a :b :c })

HTH

hitting the magical "unwrap" command would give: 

(map fooz [1 2 3] | :a  :b :c | ) 

with the keywords :a to :c selected so that I could just type "{" and I could transform the vector into a map with two keystrokes. 

Maybe I'm thinking about this in the wrong way - feedback and insights into other approaches are welcome! 
thanks,
Alex

--
You received this message because you are subscribed to the Google Groups "counterclockwise-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojuredev-use...@googlegroups.com.
To post to this group, send email to clojured...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojuredev-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alex Eberts

unread,
Apr 26, 2013, 10:04:18 AM4/26/13
to clojured...@googlegroups.com
Fantastic! That works great - I had played around with "raise over parent" before but I was selecting too much code (i.e. the outer "()" together with the expression which was clobbering the outer expression. 

One other trick that I discovered from your "State of CounterClockwise" talk , was that using "raise over parent" with the parens selected is very useful for removing trace statements, e.g.:

(trace (somefn | arg arg)) -> Shift-Alt-Up -> (trace ( | somefn  arg arg |)) -> Shift-Alt-Up -> (trace | ( somefn  arg arg ) | ) -> Raise over Parent (Alt-R) -> ( somefn  arg arg )

Maybe "raise over parent" is not the most intuitive name for newbies but it does what it says and it's damn useful. 

many thanks for the help,
Alex
To unsubscribe from this group and stop receiving emails from it, send an email to clojuredev-users+unsubscribe@googlegroups.com.
To post to this group, send email to clojuredev-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages