[slime-devel] custom indentation of macros

Chris Capel pdf23ds at gmail.com
Mon Apr 18 02:06:51 UTC 2005


I think there should be a way to specify, in a source file for a CL macro,
how SLIME should indent the macro. There is already a robust and capable,
if under-documented, way to specify the indentation for arbitrary forms in
cl-indent.el, and so it would be nice to wrap this up in a nice way and
give it some SLIME support.

My idea is to have SWANK look for a property on the CL symbols,
custom-indent-spec, that, if present, has a list (or perhaps a string
that can be read as a list in Emacs) that can be assigned to the
common-lisp-indent-function property on the Emacs symbol to modify the
indentation. It'd be nice to have some documentation for the format of
this list, too.

Anyway, here's the sort of thing I think would work.

(setf (get 'defclass-ext 'custom-indent-spec)
      '((6 4 defclass-slots-options-indent)
	(defun defclass-slots-options-indent
	    (path state indent-point sexp-column normal-indent)
	  (if (> (length path) 1)
	      (1+ sexp-column)
	      2))))

The above form is Common Lisp and contained in the source file, either
after the macro definition or somewhere else. The quoted list (caddr of
the setf form) is written in Emacs lisp. (Symbol case issues? Should
everything in the Emacs-destined form be downcased by SLIME or something?)

The first form in that list is the value the common-lisp-indent-function
property on the Emacs symbol gets set to. The subsequent forms are
function definitions that can be used in the first. My example would
allow the following indentation:

(defclass-ext some-class ()
  (slot-a :a :ia
   slot-b :a (:if 2)))

There should be some attention to name collision across packages--Emacs
lisp symbols don't have packages, so two different CL authors with a macro
with the same name and custom indentation could potentially collide in
unpleasant ways. I think what has to happen is that SLIME adds and removes
the common-lisp-indent-function property on Emacs symbols every time a
package is switched, based on what is set up for the inferior lisp's
symbols in the new package. Is this last bit feasible? Perhaps SLIME could
check to make sure the Emacs symbols have been set up with the correct
plists before every indentation, resetting them all if the package has
changed since then. Other ideas?

Chris Capel




More information about the slime-devel mailing list