formatting of maxima code



> Can any of the emacs lisp files for maxima reformat code,
> ie, putting in indentation for block structure,

maxima.el (in interfaces/emacs/emaxima/) claims to do some smart
formatting, but it has some weird conventions.  For example, to turn on
smart formatting, you must (setq maxima-indent-line 'perhaps-smart)
BEFORE loading the maxima.el file.

Its formatting is also buggy.  Consider formatting "if test then a1 else
a2", manually including NEWLINE where you want a line break.

Here are some results:

    if test then a1
      else a2,             /* Wrong, should line up with THEN */
    if test                /* OK */
      then a1
	else a2,
    if test
      then
	a1                   /* Wrong, should be more indented than THEN */
	  else               /* Arguable, but should probably be indented like
THEN */
	    a2,              /* If a1 lines up with THEN, why doesn't a2 line
up with ELSE? */

Most of the same problems with test() intead of test, but some new ones,
too.

    if test() then a1
      else a2,
    if test()
    then a1                /* Inconsistent with above */
      else a2,
    if test()
    then
      a1
	else                 /* Inconsistent with above */
	  a2,

Even worse than its, um, idiosyncratic formatting, it is not consistent
between the NEWLINE indentation and the TAB indentation.  If you go back
to the above and hit TAB at the beginning of each line, you get:

    if test then a1
    else a2,                /* Wrong */
    if test                 /* OK */
      then a1
      else a2,
    if test
      then
	a1                    /* should be more indented than THEN */
      else
	a2,                   /* should be more indented than ELSE */

Completely messed up when re-indented with TAB:

    if test() then a1 else a2,
    if test() then a1
    else a2,
    if test()
    then a1
    else a2,
    if test()
    then
      a1                     /* A little better in this case, though...
*/
    else
      a2,

> Or does anyone know about a pretty printer for maxima?

Maxima does include a pretty printer.  Just set display2d:false and
dispfun(f) will pretty-print f.  It is better than the Emacs indenter,
but far from perfect.  Note that if a construct fits on one line, it
prints it on one line -- it never puts in newlines just to show off the
structure.  So for example, f():=block([a,a],a(a),block([a,a],a(a)))
prints on one line.  But now subst
a_long_identifier_forces_multiple_lines for "a", and it will indent as
you might expect.  There is also a Maxima function called Grind (the
traditional Lisp term for pretty-printing), which simply calls the
ordinary printer after putting out a newline.  There is a trivial bug in
Grind right now, but you don't really need it anyway (and you can call
?mgrind(xxx,false) instead).

       -s