Re: standalone indentation tool

2011-08-10 Thread Tom Faulhaber
 I've tried pprint and found it lacking as it inserts newlines in
 awkward places apart from the medatada/comments issue mentioned.

Are you using pprint with code-dispatch? That tends to work a lot
better, though it will put newlines where it deems fit. This is either
a good thing or a bad thing depending your context.

It also handles all the read macros that it can:

(with-pprint-dispatch code-dispatch (pprint '#(+ % 1) ))
= #(+ % 1)

But some get eaten by the reader and are therefore impossible for
pprint to deal with (since it's working on clojure data structures and
not the raw text). These are: `, ~@, ;, ^, and the comma character.

 I think your best bet is to use Emacs from the command-line. Even if

I agree that when you're just trying to reindent human written source
code, emacs is going to produce the best results. pprint is probably
better for machine generated code, as long as you're not depending on
the macros above. (It would also be possible to annotate your code in
clojure with that and have some custom dispatch that generated those
characters as appropriate.)

HTH,

Tom

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: standalone indentation tool

2011-08-09 Thread Philipp Steinwender
thanks for that lars.
it works better. emacs does restart for each file, but it is faster than 
before because it only evaluates the code without ui.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: standalone indentation tool

2011-08-09 Thread Philipp Steinwender
sorry i didn't check the result. with --batch something went wrong. the 
indentation gets weird.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: standalone indentation tool

2011-08-09 Thread Bendlas
On Aug 7, 10:50 pm, Phil Hagelberg p...@hagelb.org wrote:
 I think your best bet is to use Emacs from the command-line. Even if
 people edit outside Emacs, it's easy to invoke for indentation
 purposes:

     $ emacs --eval (progn (find-file \badly_indented.clj\)
 (indent-region (point-min) (point-max)) (untabify (point-min)
 (point-max)) (save-buffer) (kill-emacs))

Doesn't that only replace tabs with spaces? There are some occasions
where CCW actually indents differently.
Like invocations of functions/macros prefixed by with-

kind regards

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: standalone indentation tool

2011-08-09 Thread Phil Hagelberg
On Tue, Aug 9, 2011 at 4:42 AM, Philipp Steinwender
philipp.a.steinwen...@gmail.com wrote:
 sorry i didn't check the result. with --batch something went wrong. the
 indentation gets weird.

The --batch flag causes it to skip your personal dotfiles, so you will
have to explicitly load clojure-mode.

-Phil

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: standalone indentation tool

2011-08-08 Thread Philipp Steinwender
thank you, that worked!

to re-indent all source files, I use it as bash script like:
$ find ./src ./test -name '*.clj' | xargs -I {} emacs --eval (progn (setq 
make-backup-files nil) (find-file \{}\) (indent-region (point-min) 
(point-max)) (untabify (point-min) (point-max)) (save-buffer) (kill-emacs))

it works, but it opens and closes emacs quite often. next thing for me will 
be to let emacs find all clj files and open and close them.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: standalone indentation tool

2011-08-08 Thread Lars Nilsson
On Mon, Aug 8, 2011 at 5:36 AM, Philipp Steinwender
philipp.a.steinwen...@gmail.com wrote:
 thank you, that worked!
 to re-indent all source files, I use it as bash script like:
 $ find ./src ./test -name '*.clj' | xargs -I {} emacs --eval (progn (setq
 make-backup-files nil) (find-file \{}\) (indent-region (point-min)
 (point-max)) (untabify (point-min) (point-max)) (save-buffer) (kill-emacs))
 it works, but it opens and closes emacs quite often. next thing for me will
 be to let emacs find all clj files and open and close them.

Perhaps adding --batch to the command line for emacs would be useful?

emacs --batch --eval ...

Lars Nilsson

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


standalone indentation tool

2011-08-07 Thread Philipp Steinwender
hi!

Is there a tool available that does indentation of clojure code and does not 
depend on an editor/IDE?

we work on the same code together with different editors 
(eclipse+counterclockwise and emacs). We often reindent the other's code 
what leads to changes when we merge our commits with git.
one way to fix this would be to reindent all source files with an indepedent 
tool before commiting.

Does anybody have similar problems?

Thanks in advance

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: standalone indentation tool

2011-08-07 Thread Eric Lavigne
The pprint function in the Clojure standard library indents Clojure source
code.

 http://richhickey.github.com/clojure/clojure.pprint-api.html

To get the result you are looking for, a tool would need to walk through all
the *.clj files in your source directory and, for each file, read in the
contents and pprint them back into the same file.

Bonus points for careful error checking - printing into an intermediate
buffer and reading it back in to check that nothing went wrong before
overwriting the original file.

This would make a good Leiningen plug-in, and doesn't sound too difficult to
write.

On Sun, Aug 7, 2011 at 9:17 AM, Philipp Steinwender 
philipp.a.steinwen...@gmail.com wrote:

 hi!

 Is there a tool available that does indentation of clojure code and does
 not depend on an editor/IDE?

 we work on the same code together with different editors
 (eclipse+counterclockwise and emacs). We often reindent the other's code
 what leads to changes when we merge our commits with git.
 one way to fix this would be to reindent all source files with an
 indepedent tool before commiting.

 Does anybody have similar problems?

 Thanks in advance

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: standalone indentation tool

2011-08-07 Thread Ken Wesson
On Sun, Aug 7, 2011 at 1:44 PM, Eric Lavigne lavigne.e...@gmail.com wrote:
 The pprint function in the Clojure standard library indents Clojure source
 code.
      http://richhickey.github.com/clojure/clojure.pprint-api.html
 To get the result you are looking for, a tool would need to walk through all
 the *.clj files in your source directory and, for each file, read in the
 contents and pprint them back into the same file.
 Bonus points for careful error checking - printing into an intermediate
 buffer and reading it back in to check that nothing went wrong before
 overwriting the original file.
 This would make a good Leiningen plug-in, and doesn't sound too difficult to
 write.

Er, won't you lose all comments and have reader macros expanded if you
use read/pprint to do the transformation?

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: standalone indentation tool

2011-08-07 Thread Eric Lavigne


  The pprint function in the Clojure standard library indents Clojure
 source
  code.
   http://richhickey.github.com/clojure/clojure.pprint-api.html

 Er, won't you lose all comments and have reader macros expanded if you
 use read/pprint to do the transformation?


Oops. I think I could live without comments (Docstrings all the way!),

but I don't want

 #(+ % 1)

turning into

 (fn* [p1__945#] (+ p1___945# 1))

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: standalone indentation tool

2011-08-07 Thread Alan Malloy
On Aug 7, 11:10 am, Eric Lavigne lavigne.e...@gmail.com wrote:
   The pprint function in the Clojure standard library indents Clojure
  source
   code.
        http://richhickey.github.com/clojure/clojure.pprint-api.html

  Er, won't you lose all comments and have reader macros expanded if you
  use read/pprint to do the transformation?

 Oops. I think I could live without comments (Docstrings all the way!),

 but I don't want

      #(+ % 1)

 turning into

      (fn* [p1__945#] (+ p1___945# 1))

You would also lose all the newlines, and there's no way pprint would
put them in places as intelligent as you would.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: standalone indentation tool

2011-08-07 Thread Phil Hagelberg
On Sun, Aug 7, 2011 at 6:17 AM, Philipp Steinwender
philipp.a.steinwen...@gmail.com wrote:
 Is there a tool available that does indentation of clojure code and does not
 depend on an editor/IDE?
 we work on the same code together with different editors
 (eclipse+counterclockwise and emacs). We often reindent the other's code
 what leads to changes when we merge our commits with git.
 one way to fix this would be to reindent all source files with an indepedent
 tool before commiting.

I've tried pprint and found it lacking as it inserts newlines in
awkward places apart from the medatada/comments issue mentioned.

I think your best bet is to use Emacs from the command-line. Even if
people edit outside Emacs, it's easy to invoke for indentation
purposes:

$ emacs --eval (progn (find-file \badly_indented.clj\)
(indent-region (point-min) (point-max)) (untabify (point-min)
(point-max)) (save-buffer) (kill-emacs))

-Phil

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en