I'm using Counterclockwise but unfortunately they haven't implemented this functionality yet. Do you have any ideas how can I format my Clojure code automatically in the "lispy" way?

- 62,768
- 50
- 234
- 356

- 29,285
- 22
- 112
- 207
-
Didn't check out the plugin, but they say that they do have auto-indentation. That doesn't work for you? – Marko Topolnik Apr 24 '12 at 20:10
-
I think that what they mean by auto indentation is when I press the tab button it automatically indents the code according to the structure of the code above the cursor (+1 tab if there was an if in the upper line for example). What I'm looking for is Formatting which is not yet implemented according to their documentation. – Adam Arold Apr 24 '12 at 20:27
-
I work in emacs and all you get there is auto-indent, so I'm wondering what this might mean. Would it mean splitting the lines automatically? Can you point me to some reading? – Marko Topolnik Apr 24 '12 at 20:33
-
7in intellij idea (la clojure plugin) ctrl-alt-L reindents the entire file. is that the kind of thing the original poster is looking for? i think there's a free intellij idea you can download, so that might be a solution (i use emacs and eclipse in various places, but intellij idea is the one piece of software i pay for - otherwise i am unconnected with them). – andrew cooke Apr 24 '12 at 21:26
-
Yes, that's exactly what I'm looking for. I was not convinced by IntelliJ IDEA altough I tried it several weeks ago. – Adam Arold Apr 24 '12 at 22:06
-
@MarkoTopolnik In emacs select a region, then Esc C-\, and it will format the region. – BillRobertson42 Jan 09 '13 at 14:37
-
@Bill C-M-\ is **indent-region**: it only reindents. My question was sepecifically about **reformatting**, which implies changing line breaks. – Marko Topolnik Jan 09 '13 at 14:41
-
2And I'm not talking about Emacs either. – Adam Arold Feb 19 '13 at 23:01
-
This is a large hack, but you could try executing the built-in [`pprint`] (http://richhickey.github.com/clojure/doc/clojure/pprint/PrettyPrinting.html) in the REPL, then paste your whole buffer in as the argument. :) – Eric Galluzzo Feb 23 '13 at 22:31
-
Adam, neither the question nor your comments make clear what you actually want. Reformat an existing clojure file? Syntax highlighting? Or just automatic indenting when you start a new line while in an unfinished s-expression? I used counterclockwise about a year ago, and apart from reformating an existing file (which I've just no clue about), pretty much everything was working. Hilighting, formatting, execution, etc. Please say what you're looking for specifically. – Alex Apr 16 '13 at 13:53
-
Others seem to understand it. My comments explicitly state what I wished for. This implicates something about your cognitive capacity. I'm sorry. – Adam Arold Apr 16 '13 at 14:42
-
Your comments only say what you do not want: no tab button, no Intellij, no Emacs. So let's settle for you want to reformat an existing file. Also, how about sharing what you came up with in the end? – Alex Apr 16 '13 at 15:21
-
There is no soution yet. You clearly can't interpret the comments here so let's just stop talking about this. I won't comment on it further. – Adam Arold Apr 16 '13 at 15:27
3 Answers
In the latest version of the Counterclockwise IDE you can simply select all in a file Ctrl+A then press Ctrl+I for "Indent the current line" to properly indent the whole file.
Pressing Tab (regardless of cursor position) will do the same for the line where the cursor resides but it won't work when all lines are selected.

- 29,285
- 22
- 112
- 207
There doesn't seem to be a "finished" Clojure indenter for Eclipse and I don't know enough about Eclipse to write one. But there is pretty-printing capability available in Clojure (contrib) itself:
http://richhickey.github.com/clojure-contrib/pprint-api.html
... so what I would do if I was in your situation and really tired of not being able to indent code is to write a little GUI app (you could do it in Clojure for fun and practice) that allows you to cut&paste your code into a TextArea, reformats it on demand and stuffs the formatted code back into the clipboard for you. A clunky solution but one that's fairly easy to implement.

- 66,391
- 18
- 125
- 167
-
@Octopus please indicate if you wish to accept this message. It is irrelevant for me since I started using another IDE. – Adam Arold Feb 26 '13 at 12:22
-
You mean award the bounty, right? I can't accept an answer for your question. I am waiting to see if there other answers. – octopusgrabbus Feb 26 '13 at 19:15
Counter Clockwise version 0.20.0 (October 2013) added a "reindent selection" capability. I know that's not all you wanted, but it's a start.

- 15,480
- 3
- 61
- 91