Fork me on GitHub
#editors
<
2015-07-17
>
cfleming08:07:37

I’m still interested in feedback on the best way to select Clojure forms. Do people like CCW-style selection left/right extension? Something like mark-sexp? Move left/right while selecting?

colin.yates08:07:35

IIRC the expanding selection was restricted to just the form? I would find it really useful if it then expanded to outer forms, so if cursor is between the ‘ll' (defn something [] (println “hello”)) I could expand once to select “hello”, expand again to select (println “hello”), expand again to select (defn….)

colin.yates08:07:40

(is that what you are asking?)

colin.yates08:07:29

At the moment I tend to move to front of the form and Cntr-Alt-delete

cfleming08:07:11

You can do what you want there with repeated alt-up

cfleming08:07:42

That will select hello, “hello”, (println “hello”), (defn …) etc etc

cfleming08:07:27

The tricky bit is selecting two (or more) forms which are siblings

cfleming08:07:02

Emacs has mark-sexp, which marks the next sexp, and repeated invocations continues marking subsequent forms

cfleming08:07:18

CCW has expand selection left/right

cfleming08:07:59

A few people have asked for a version of move left/right which marks as you go, or if the movement commands could automatically expand/contract the selection.

colin.yates08:07:48

I can’t see how I would use the left/right as that would surely mean your selection is unbalanced?

cfleming09:07:28

No - say you have:

(defn test []
  |(some-form)
  (some-other-form)
  (yet-another-form))

cfleming09:07:54

Where | is the caret

cfleming09:07:52

If you alt-up there, you’ll select (some-form). mark-sexp would select (some-form), then if you do it again you’d have (some-form)\n(some-other-form) selected, and so on.

cfleming09:07:08

So it’s for selecting multiple sibling forms. It’s something I want to do a surprising amount of the time. But all the options have a tricky balance between simplicity, flexibility, and adding a ton of commands (which all need keybindings etc)

colin.yates09:07:11

ah OK, so you start outside the form. Yeah, I need that. The closest I have come is shift and down to highlight the lines and then shift+alt+left/right to end the selection. Muscle memory makes it not too painful

cfleming09:07:46

Yeah, it’s still pretty horrible, though - that’s what I end up doing too.

cfleming09:07:37

CCW style marking doesn’t require you to be outside the form - you could be inside (some-form), alt-up a couple of times to select it, then extend selection right.

colin.yates09:07:11

I see. Yes from me then.

cfleming09:07:46

Not so fast. Note that you’ll need probably 4 new commands - extend/shrink left/right.

cfleming09:07:53

And keys for them.

colin.yates09:07:34

oh I see. So the ‘native’ IntelliJ selection isn’t sexp aware. Right.

cfleming09:07:06

Well, it is because Cursive extends it. But it’s purely hierarchical, up/down the sexp tree, not laterally into siblings.

colin.yates09:07:04

I am reacting here, rather than thinking deeply, but couldn’t you make the behaviour you described the default behaviour in Clojure files? When would you not want the behaviour you described when selecting?

cfleming09:07:30

The problem is that the expand/shrink selection is baked into IntelliJ. I use it all the time in Java, for example.

cfleming09:07:46

Anyone used to IntelliJ will go wild if that gets broken.

cfleming09:07:57

I can reasonably trivially add extend left/right, but then you also probably need shrink left/right in case you accidentally go too far.

cfleming09:07:07

And then you need 4 new keybindings.

cfleming09:07:22

Presumably in very convenient locations.

colin.yates09:07:59

And not ‘wild’ in a good way I guess. It has been so long since I did anything in IntelliJ other than Clojure I forgot IntelliJ is used for other things 😉

cfleming09:07:19

In CCW, I guess Eclipse doesn’t have the expand/contract baked in, so there up is expand selection, left and right extend left and right, and down is “undo what I last did”.

cfleming09:07:30

Which would be really nice but I can’t do it.

cfleming09:07:54

Yeah, a few people also use it for other stuff simple_smile

colin.yates09:07:21

and you can’t use this as a reason to get them to drop Java and pick up Clojure….. yeah OK, maybe not 😉

cfleming09:07:55

Additionally “undo what I last did” in IntelliJ is tricky because selection is complicated - multiple cursors, column selection mode, ugh

colin.yates09:07:02

Yeah - undo-tree in emacs has spoilt all editors for me on that front. IntelliJ’s history is pretty close

cfleming09:07:24

Yeah, something like undo-tree would be really nice.

cfleming09:07:53

Although this is a different kind of undo that only works on selections, since in IntelliJ at least undo doesn’t undo selection actions.

cfleming09:07:24

Anyway, I’m just moaning now - I’m going to try a few things and see how they work.

colin.yates09:07:11

well for me, I could live in selection behaving one way in a Clojure file and a different way in a non-Clojure file as long as the semantics were the same.

colin.yates09:07:46

I am sure what you come up with will be excellent based on previous experience Colin - I really don’t think I/we can say thank you enough.

cfleming09:07:05

Here’s hoping - thanks!

cfleming09:07:17

Paredit is much nicer in the next build.