Code formatting utility for Clojure in Eclipse
Asked Answered
C

3

22

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?

Cobra answered 24/4, 2012 at 17:59 Comment(13)
Didn't check out the plugin, but they say that they do have auto-indentation. That doesn't work for you?Delouse
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.Cobra
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?Delouse
in 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).Downatheel
Yes, that's exactly what I'm looking for. I was not convinced by IntelliJ IDEA altough I tried it several weeks ago.Cobra
@MarkoTopolnik In emacs select a region, then Esc C-\, and it will format the region.Cohort
@Bill C-M-\ is indent-region: it only reindents. My question was sepecifically about reformatting, which implies changing line breaks.Delouse
And I'm not talking about Emacs either.Cobra
This is a large hack, but you could try executing the built-in [pprint] (richhickey.github.com/clojure/doc/clojure/pprint/…) in the REPL, then paste your whole buffer in as the argument. :)Excursionist
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.Subtorrid
Others seem to understand it. My comments explicitly state what I wished for. This implicates something about your cognitive capacity. I'm sorry.Cobra
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?Subtorrid
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.Cobra
C
7

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.

Cobra answered 3/4, 2014 at 21:26 Comment(0)
F
3

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.

February answered 25/2, 2013 at 21:27 Comment(2)
@Octopus please indicate if you wish to accept this message. It is irrelevant for me since I started using another IDE.Cobra
You mean award the bounty, right? I can't accept an answer for your question. I am waiting to see if there other answers.Fortuitous
R
1

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.

Reliquiae answered 12/2, 2014 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.