[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

slime indentation of macros

Jim Newton

1/5/2016 2:12:00 PM

I see that slime understands how to indent macros which contain an &body in the lambda list.
But is there a way to tell slime to indent a particular macro "like" some other one.
For example, I have a macro optimized-typecase which i would like to be indented the same
as typecase.

Is this possible?

3 Answers

Didier Verna

1/5/2016 3:35:00 PM

0

Jim Newton wrote:

> I see that slime understands how to indent macros which contain an
> &body in the lambda list. But is there a way to tell slime to indent
> a particular macro "like" some other one. For example, I have a macro
> optimized-typecase which i would like to be indented the same as
> typecase.

Technically, it's not Slime, it's Emacs. Look at the function (and the
symbol property called) common-lisp-indent-function. Also, you may
want to read http://www.didierverna.net/blog/index.php?post/2011/07/20/One-more-indent...

--
@-quartet live: Sunset/Sunside, Paris, Jan 26 2016 !
Book now: http://www.sunset-sunside.com/2016/1/artiste/...

Lisp, Jazz, Aïkido: http://www.didier...

Jim Newton

1/5/2016 4:47:00 PM

0

Thanks for the links. It seems that, for example, common-lisp TYPECASE is indented the way it is
because the elisp symbol typecase has a property on it named common-lisp-indent-function.

> Technically, it's not Slime, it's Emacs. Look at the function (and the
> symbol property called) common-lisp-indent-function. Also, you may
> want to read http://www.didierverna.net/blog/index.php?post/2011/07/20/One-more-indent...

Furthermore, it seems (from the blog) that if I define the functions beforehand (in a way that
anyone else loading the code also defines the function), then before the (defmacro optimized-typecase ...)
I may also include something like (defindent optimized-typecase typecase)

What would be great is if I could do the following. (inspired by a conversation between me and Thomas Burdick several years ago)

(defmacro optimized-typecase (obj &rest clauses)
(declare (slime-indent (as typecase)))
...)

Correct me if I'm wrong, but I believe conforming CL implementations are required to ignore
declarations they don't understand. Thus, such a declaration would do no harm if someone
loads/compiles the code in an environment that does not use slime.

I looked at the swank code for symbol-indent and macro-indentation, and it is not clear to me
how I would access the declarations at this point. I.e., we'd need to access the declarations
triggered by an even at the macro invocation site, but the declarations appear at the macro definition
site.


Pascal J. Bourguignon

1/5/2016 7:13:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> What would be great is if I could do the following. (inspired by a
> conversation between me and Thomas Burdick several years ago)
>
> (defmacro optimized-typecase (obj &rest clauses)
> (declare (slime-indent (as typecase)))
> ...)
>
> Correct me if I'm wrong, but I believe conforming CL implementations
> are required to ignore
> declarations they don't understand. Thus, such a declaration would do
> no harm if someone
> loads/compiles the code in an environment that does not use slime.

As long as you declare it!

(declaim (declaration slime-indent))

then you can use it as above.

Notice: you may want to use a symbol in a specific package for your
declarations.


> I looked at the swank code for symbol-indent and macro-indentation,
> and it is not clear to me
> how I would access the declarations at this point. I.e., we'd need to
> access the declarations
> triggered by an even at the macro invocation site, but the
> declarations appear at the macro definition
> site.

You would have to read the defun form, and parse it.
Alternatively, you may shadow cl:defun and define a defun macro that
takes the declaration into account.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk