Fun with lisp

While hacking my emacs mud client, I wanted to add some convenience functions for tweaking typefaces in a friendlier way than emacs normally allows.

The mud client stores per-mud information in a property list attached to a symbol, by convention stored in a variable called mud-current. Anything you want to know about a given mud can be determined through (get mud-current 'propertyname), for arbitrary values of propertyname.

Fonts are included in this property list, so I figured I'd need to allow people to select fonts applicable to their selected mud. completing-read is good for this sort of stuff as it stops you making typos so much.

So, how to make the completion list? (symbol-plist SYMBOL) returns a list of (propname propvalue propname propvalue ...), so I guessed I'd just do a (facep SYMBOL) on each element and add it to a list. Hmm. I could use (mapcar FUNCTION LIST) for that...

(mapcar '(lambda(x) (if (facep x) x nil)) (symbol-plist mud-current))

Doh! Problem. This gives me a whole heap of nil in my list. Easily fixed:

(delq nil (mapcar '(lambda(x) (if (facep x) x nil)) (symbol-plist mud-current)))

Right, now I have a list of faces; let's see what it looks like.

DOH! It only gives me the values, and I need the propnames as well. Actually, what I really need is to attach the propnames to the properties, and dump all of them into a list if the properties are faces, and...

(delq nil 
  (let (y) 
    (mapcar '(lambda(x)
               (if y 
                 (let ((z (cons y x)))
                   (setq y nil)
                   (if (facep x) 
                     z 
                   nil))
                 (setq y x)
                 nil))
            (symbol-plist mud-current))))

Hey, whaddya know? It works!


Waider I'd explain it to you, but your brain would explode.