[comp.soft-sys.andrew] ltext improvements

rdh@THUMPER.BELLCORE.COM (Ralph Hill) (03/23/91)

Ltext mode knows about and formats some ``functions'' in a special way. 
For example

    (defun foo ()
      (body-of-foo))

vs.

    (foo-bar foo ()
                 body-of-foo))

For certain special forms, it knows that there are some parameters that
are indented in one way, and others that are indented in another way. 
For defuns, there are two special parameters.

This is fine, until you get CLOS, and try this:

    (defmethod foo (..)
               (body-of-foo))

You march to the right very fast.  You would like to tell ltext that
defmethod is like defun.  Unfortunately, as distributed, the table is
coded in.

Here is a patch that defaults to the old behavior, but will read the
table from your preferences.

Here is a diff...   ltext.c is in atk/contrib/ltext

diff *ltext.c originals/*ltext.c
15d14
< #include <environ.ih>
769,770c768,775
<     int indent;
<     char *t, *t2, *s = environ_GetProfile("ltextindents");
---
>     addindent("defun", 2);
>     addindent("defmacro", 2);
>     addindent("defconstant", 1);
>     addindent("defstruct", 1);
>     addindent("let", 1);
>     addindent("let*", 1);
>     addindent("do", 2);
>     addindent("if", 1);
772,781d776
<     if (!s) s =
"defun:2,defmacro:2,defconstant:1,defstruct:1,let:1,let*:1,do:2,if:1";
<     while (t = s) {
<         s = index(t, ',');
<         if (s) *s++ = NULL;
<         t2=index(t, ':');
<         if (t2) *t2++=NULL;
<         indent = t2 ? atoi(t2) : 1;
<         addindent(t, indent);
<     }
<   


You want to add a line like this to your preferences file:

*.ltextindents:defun:2,defmacro:2,defconstant:1,defstruct:1,let:1,let*:1,do:2,i
f:1

This will give you the default behavior.  You give the name of the
``function'', a colon, and the number of special parameters.  Commas are
used as separators.  The number of special parameters defaults to 1.  In
general, aiming low on the number is a lot better than aiming high. 
Case is ignored for the names.

This is what I use right now (I am not finished tuning):

*.ltextindents:defun:2,defmacro:2,defconstant:1,defstruct:1,let:1,let*:1,do:2,i
f:1,defclass:2,defmethod:2,dolist:1,progn:0,when:1,unless:1,loop:1

I use Common Lisp with CLOS.

We are using:

ez (Version 7.0, ATK 15.1)



  ralph hill

P.S.  If you are having tab problems with ltext's (or ctext's?) pretty
printing, try this in your .ezinit:

addfiletype .cl ltext "ltext-use-tabs=0"
addfiletype .eli ltext "ltext-use-tabs=0"
addfiletype .c ctext "ctext-use-tabs=0"

help ltext says to do this, but who reads documentation?  Not me!  I
suffered for months.