I have some lisp/scheme-like code which I want to indent.
I searched for tools like GNU indent
, but I could not find any
command-line utility/script. There are lots of them available for
C/C++/Java ,but somehow I am unable to find any for lisp/scheme,
can anyone please let me know of any such indentation tools if available.
Thanks.
You could use emacs
in batch mode. For example, you could create a file indent.el
(defun my/indent-file (fPath)
(let ((buffer (find-file fPath)))
(message (concat "indenting file " fPath))
(indent-region (point-min) (point-max))
(save-buffer)
(kill-buffer buffer)))
(mapcar 'my/indent-file argv)
and then call emacs like this to indent a bunch of files (note that it will work for any language emacs can recognize and knows how to indent):
emacs --load indent.el --batch MY_LISP_FILES
See e.g. this page to get more information about idiomatic ways to use emacs
for batch processing.
Edit
Here is a one-liner which works only on one file but doesn't use the argv
variable (beware: the arguments order is important):
emacs --batch MY_FILE --eval '(indent-region (point-min) (point-max))' -f 'save-buffer'
If you use vim, this post should give you a way to run vim's auto indent command on all files. And if you want (IMO) really good indenting of lisp files in vim, I recommend loading slimv and the swank server before running that command.
Here's my ambitious attempt at creating a decent batch mode indenter codenamed yasi(yet another s-expression indenter). If for some reason it doesn't win you over(it's about 800
lines), you can fallback to lispindent2.lisp
which is basically Dorai's original indenter(lispindent.lisp
) with some tweaks here and there. lispindent2.lisp
is a batch mode indenter that is as lean as the original one(added about 65 lines) but still indents beautifully.
Dorai Sitaram has the scmindent.scm
and lispindent.lisp
scripts on this website that will work for that purpose. They were originally intended to let you indent Lisp code in vi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With