Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

external lisp code indenter

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.

like image 585
vyom Avatar asked Mar 22 '12 14:03

vyom


4 Answers

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' 
like image 130
François Févotte Avatar answered Nov 15 '22 08:11

François Févotte


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.

like image 44
Clayton Stanley Avatar answered Nov 15 '22 09:11

Clayton Stanley


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.

like image 38
Plakhoy Avatar answered Nov 15 '22 09:11

Plakhoy


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.

like image 36
Asumu Takikawa Avatar answered Nov 15 '22 09:11

Asumu Takikawa