From: Spiros Bousbouras
Subject: indent for CL
Date: 
Message-ID: <19013e59-e201-4520-b270-a7829000f98c@i29g2000prf.googlegroups.com>
Is there any tool for indenting/reformatting
CL source so that it agrees with common
indenting conventions ? So I'm looking for
something which does for CL what the common
Unix utility "indent" does for C source. I
googled the group and only saw references
to some Emacs commands which *might*
do what I want. But I'm looking for something
which is not interactive but for example reads
from stdin (or a file) and writes on stdout.

If no such tool exists how hard would it be to
write one ? I would imagine easier than the
corresponding C tool. Is there any place which
lists all the indenting conventions ?

From: Pascal Bourguignon
Subject: Re: indent for CL
Date: 
Message-ID: <87d4pdpms0.fsf@thalassa.informatimago.com>
Spiros Bousbouras <······@gmail.com> writes:

> Is there any tool for indenting/reformatting
> CL source so that it agrees with common
> indenting conventions ? So I'm looking for
> something which does for CL what the common
> Unix utility "indent" does for C source. I
> googled the group and only saw references
> to some Emacs commands which *might*
> do what I want. But I'm looking for something
> which is not interactive but for example reads
> from stdin (or a file) and writes on stdout.
>
> If no such tool exists how hard would it be to
> write one ? I would imagine easier than the
> corresponding C tool. 

Something like this:

#!/bin/bash
trap 0 "rm /tmp/$$.lisp"
cat > /tmp/$$.lisp
emacs -batch -eval "(progn (find-file \"/tmp/$$.lisp\") (indent-region (point-min) (point-max)) (save-buffer 0) (kill-emacs))"
cat /tmp/$$.lisp


Or like this:

#!/usr/bin/clisp -q -a
(loop ; this one won't copy the comments :-(
  :for form = (read *standard-input* nil *standard-input*)
  :until (eq form *standard-input*)
  :do (pprint form *standard-output*) (terpri))


> Is there any place which
> lists all the indenting conventions ?

No.  As soon as you invent a new macro, you have a new indenting to
define for that macro.  We can infer some default indenting for it
depending on the given macro-lambda-list, but this wouldn't work for
macros with &rest args and that parse them at will.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Our users will know fear and cower before our software! Ship it!
Ship it and let them flee like the dogs they are!"
From: ···········@gmail.com
Subject: Re: indent for CL
Date: 
Message-ID: <d2b92894-b3f7-4f1f-b5ca-a3b55d82c2e6@d62g2000hsf.googlegroups.com>
On Mar 29, 11:34 am, Pascal Bourguignon <····@informatimago.com>
wrote:
> Spiros Bousbouras <······@gmail.com> writes:
> > Is there any tool for indenting/reformatting
> > CL source so that it agrees with common
> > indenting conventions ? So I'm looking for
> > something which does for CL what the common
> > Unix utility "indent" does for C source. I
> > googled the group and only saw references
> > to some Emacs commands which *might*
> > do what I want. But I'm looking for something
> > which is not interactive but for example reads
> > from stdin (or a file) and writes on stdout.
>
> > If no such tool exists how hard would it be to
> > write one ? I would imagine easier than the
> > corresponding C tool.
>
> Something like this:
>
> #!/bin/bash
> trap 0 "rm /tmp/$$.lisp"
> cat > /tmp/$$.lisp
> emacs -batch -eval "(progn (find-file \"/tmp/$$.lisp\") (indent-region (point-min) (point-max)) (save-buffer 0) (kill-emacs))"
> cat /tmp/$$.lisp

Dumb question, what does the $$ mean here?
>
> Or like this:
>
> #!/usr/bin/clisp -q -a
> (loop ; this one won't copy the comments :-(
>   :for form = (read *standard-input* nil *standard-input*)
>   :until (eq form *standard-input*)
>   :do (pprint form *standard-output*) (terpri))
>
> > Is there any place which
> > lists all the indenting conventions ?
>
> No.  As soon as you invent a new macro, you have a new indenting to
> define for that macro.  We can infer some default indenting for it
> depending on the given macro-lambda-list, but this wouldn't work for
> macros with &rest args and that parse them at will.
>
> --
> __Pascal Bourguignon__                    http://www.informatimago.com/
>
> "Our users will know fear and cower before our software! Ship it!
> Ship it and let them flee like the dogs they are!"
From: vanekl
Subject: Re: indent for CL
Date: 
Message-ID: <fsp7n9$n07$1@aioe.org>
···········@gmail.com wrote:
> On Mar 29, 11:34 am, Pascal Bourguignon <····@informatimago.com>
> wrote:
>> Spiros Bousbouras <······@gmail.com> writes:
>>> Is there any tool for indenting/reformatting
>>> CL source so that it agrees with common
>>> indenting conventions ? So I'm looking for
>>> something which does for CL what the common
>>> Unix utility "indent" does for C source. I
>>> googled the group and only saw references
>>> to some Emacs commands which *might*
>>> do what I want. But I'm looking for something
>>> which is not interactive but for example reads
>>> from stdin (or a file) and writes on stdout.
>>> If no such tool exists how hard would it be to
>>> write one ? I would imagine easier than the
>>> corresponding C tool.
>> Something like this:
>>
>> #!/bin/bash
>> trap 0 "rm /tmp/$$.lisp"
>> cat > /tmp/$$.lisp
>> emacs -batch -eval "(progn (find-file \"/tmp/$$.lisp\") (indent-region (point-min) (point-max)) (save-buffer 0) (kill-emacs))"
>> cat /tmp/$$.lisp
> 
> Dumb question, what does the $$ mean here?
[snip]

$$ == current process id (PID), commonly used to
represent a temp file name when doing shell scripting.

execute "echo $$" (w/o the quotation marks) in a bash or
bourne shell and you'll see.
From: Spiros Bousbouras
Subject: Re: indent for CL
Date: 
Message-ID: <d658b1b1-4e06-4dc7-9cde-c52c4f6e6dd9@e10g2000prf.googlegroups.com>
On 29 Mar, 16:34, Pascal Bourguignon <····@informatimago.com> wrote:
> Spiros Bousbouras <······@gmail.com> writes:
> > Is there any tool for indenting/reformatting
> > CL source so that it agrees with common
> > indenting conventions ? So I'm looking for
> > something which does for CL what the common
> > Unix utility "indent" does for C source. I
> > googled the group and only saw references
> > to some Emacs commands which *might*
> > do what I want. But I'm looking for something
> > which is not interactive but for example reads
> > from stdin (or a file) and writes on stdout.
>
> > If no such tool exists how hard would it be to
> > write one ? I would imagine easier than the
> > corresponding C tool.
>
> Something like this:
>
> #!/bin/bash
> trap 0 "rm /tmp/$$.lisp"
> cat > /tmp/$$.lisp
> emacs -batch -eval "(progn (find-file \"/tmp/$$.lisp\") (indent-region (point-min) (point-max)) (save-buffer 0) (kill-emacs))"
> cat /tmp/$$.lisp
>
> Or like this:
>
> #!/usr/bin/clisp -q -a
> (loop ; this one won't copy the comments :-(
>   :for form = (read *standard-input* nil *standard-input*)
>   :until (eq form *standard-input*)
>   :do (pprint form *standard-output*) (terpri))

Great , thanks. I was hoping for something smaller
than emacs or a CL compiler but I guess these will
have to do for now.

>
> > Is there any place which
> > lists all the indenting conventions ?
>
> No.  As soon as you invent a new macro, you have a new indenting to
> define for that macro.

Now I'm confused. If there aren't any conventions
how do emacs and clisp manage ? I assume they use
algorithms which embody the conventions. Anyway
can you give me an example of how a macro defines
a new indenting ?

For anyone with similar questions to mine there's
also
http://groups.google.co.uk/group/comp.lang.lisp/browse_thread/thread/e95564e3550bbcfd
which I missed in my original search.
From: Alessio Stalla
Subject: Re: indent for CL
Date: 
Message-ID: <b760dfe4-695d-4495-8d76-3d78435a7b0e@d1g2000hsg.googlegroups.com>
> Now I'm confused. If there aren't any conventions
> how do emacs and clisp manage ? I assume they use
> algorithms which embody the conventions. Anyway
> can you give me an example of how a macro defines
> a new indenting ?

(defmacro if2 (&rest args)
  (destructuring-bind (cond then else) args
    `(if ,cond ,then ,else)))

That's just a silly example, but you should get the point - emacs
won't know this macro should be indented like IF. In general the
algorithms used by editors to indent Lisp code are not that complex,
they just follow some conventions (e.g. the use of &body, macros whose
name starts in WITH- or DEF, etc).

HTH, Alessio Stalla
From: Pascal Bourguignon
Subject: Re: indent for CL
Date: 
Message-ID: <87hcemoev7.fsf@thalassa.informatimago.com>
Alessio Stalla <·············@gmail.com> writes:

>> Now I'm confused. If there aren't any conventions
>> how do emacs and clisp manage ? I assume they use
>> algorithms which embody the conventions. Anyway
>> can you give me an example of how a macro defines
>> a new indenting ?
>
> (defmacro if2 (&rest args)
>   (destructuring-bind (cond then else) args
>     `(if ,cond ,then ,else)))
>
> That's just a silly example, but you should get the point - emacs
> won't know this macro should be indented like IF. In general the
> algorithms used by editors to indent Lisp code are not that complex,
> they just follow some conventions (e.g. the use of &body, macros whose
> name starts in WITH- or DEF, etc).

In the case of emacs, you can tell it how to indent adding a
lisp-indent-function property to the symbol.

Read the documentation of the emacs function lisp-indent-function for details.

In simple cases, you just put the number of arguments that must be
indented specially:

(your-macro x y z ; 3 arguments
   a
   b
   c 
   d)

(your-macro 
      x
      y
      z
   a
   b
   c
   d)

==> 

#+emacs
(put 'your-macro 'lisp-indent-function 3)


But a macro like defmethod, which takes optional keywords before the
parameter list would need more sophisticaed a lisp-indent-function
property.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.