Michael Weber: Random Bits and Pieces

...Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list.

Kent M. Pitman

Lisp Logo (by Conrad Barsky)

If your Common Lisp DEFCLASS forms have been looking like fruit salad, despair not! GNU/Emacs and mwe-defclass-formatter.el to the rescue:

Before:


(defclass identifier ()
  ((name :reader name-of :initarg :name)
   (location :reader location-of :initarg :location)
   (scope         :accessor scope-of :initarg :scope)
   (definition :accessor definition-of :initform nil))
  (:default-initargs :scope *current-scope*))

After M-x mwe:align-defclass-slots RET:


(defclass identifier ()
  ((name       :reader   name-of       :initarg  :name)
   (location   :reader   location-of   :initarg  :location)
   (scope      :accessor scope-of      :initarg  :scope)
   (definition :accessor definition-of :initform nil))
  (:default-initargs :scope *current-scope*))

Existence of this code snippet is clearly a proof that soccer does not deserve my full attention. I can do many other useless things at the same time!

Should this go into cl-indent.el? If so, whose version?

UPDATE 2006-06-27: Emacs Compatibility Issues

Stefan Kamphausen kindly wrote in to tell that my code works in recent Emacsen only:

I just tried your formatting function and it failed. You seem to be using a very recent version of just-one-space which takes an argument. My XEmacs as well as the GNU Emacs installed on my system don't feature such a version. I tried to come up with a little helper function and it seems to work fine. Maybe this is interesting to you.

(defun ensure-spaces (num)
  "Helper function when you don't have a recent `just-one-space'."
  (just-one-space)
  (if (= num 0)
    (backward-delete-char)
    (loop repeat num
          do
          (insert " "))))

For what it's worth, here is my GNU/Emacs's just-one-space (version 22.0.50.1):


(defun just-one-space (&optional n)
  "Delete all spaces and tabs around point, leaving one space (or N spaces)."
  (interactive "*p")
  (let ((orig-pos (point)))
    (skip-chars-backward " \t")
    (constrain-to-field nil orig-pos)
    (dotimes (i (or n 1))
      (if (= (following-char) ?\s)
	  (forward-char 1)
	(insert ?\s)))
    (delete-region
     (point)
     (progn
       (skip-chars-forward " \t")
       (constrain-to-field nil orig-pos t)))))

UPDATE 2008-01-08: Old News...

The above functionality is part of Redshank mode now.