I have a function definition like so:
(defn init-globals [] (def *board-width* 15))
I want to be able to reformat so that it looks something like:
(defn init-globals []
(def *board-width* 15))
I would like the formatting to be done by an intelligent agent that doesn't merely indent everything a fixed amount, or just prints one element per line etc. This is something that perltidy does.
perltidy takes code like:
sub foo {
my $args = shift; $a = $args->{a}; $long_var = $args->{b}; }
and turns it into:
sub foo {
my $args = shift;
$a = $args->{a};
$long_var = $args->{b};
}
Notice how it considers the "sub" defintion as a whole, and even the "=" on the last two assignments line up. While I don't necessarily need this level of formatting, I would like something that takes a list (or more accurately, a form), that is a function with args and subexpressions, and makes it as human readable as possible.
The reason my function definition is a single line is because it's generated from a macro. I don't want to clutter up the macro with formatting instructions (if indeed I can even do this without generating a string instead of a list) because macros are hard enough as it is. While I can eval the list into my REPL just fine, I would also like to write the generated code to a file as if it were typed in by hand i.e something you could check into source control.
I've looked at things like (clojure.pprint/pp), and using emacs 'indent-sexp and smartparen's 'sp-indent-defun, but they don't split the output into multiple lines among other things.
I can interop with emacs/elisp commands, so if there's a way to do it with emacs, that would work too.
[:emacs]
and it'll do it for you ;) – iced