The thing that I do endlessly in my
(global-set-key "\M-x" 'this_command)
(global-set-key "\M-y" '(lambda () (interactive)
(this) (that) (the-other))) and
(global-unset-key "\M-z"). It was awful.
It finally occurred to
me to simplify things a bit with a single macro,
so that I can do
(onkey "\M-x" 'this_command) and
(this) (that) (the-other)) and
(onkey "\M-z" nil).
It's my first Lisp macro, and it is scary.
And here it is:
(defmacro onkey (key &rest body) (cond
(zerop (length body))
; no params at all
(and (= 1 (length body))
(null (car body))))
; one param: nil
(list 'global-unset-key key))
; symbolp doesn't work nicely in
; macros, it seems. So we fake it.
(= 1 (length body))
(listp (car body))
(string-equal (caar body) 'quote))
(list 'global-set-key key (car body)))
((listp (car body)) ; commands
(list 'global-set-key key
(append '(lambda () "~keyfunction~"
"I don't understand this onkey parameter: %s"