» matching sexps in emacs lisp

Tuesday, 11 December A.D. 2012 @ 8:01 AM

Occasionally, you come across a piece of code that looks quite complicated. And then you realize that the code is really overcomplicating the situation, not that the task is inherently difficult. Today's specimen:

(defun icalendar--convert-block-to-ical (nonmarker entry-main)
  "Convert block diary entry to iCalendar format.
NONMARKER is a regular expression matching the start of non-marking
entries.  ENTRY-MAIN is the first line of the diary entry."
  (if (string-match (concat nonmarker
                            "%%(diary-block \([^ /]+[ /]+[^ /]+[ /]+[^ ]+\)"
                            " +\([^ /]+[ /]+[^ /]+[ /]+[^ ]+\))\s-*"
                            "\s-*\(.*?\) ?$")

All of the line noise after diary-block is manually matching subexpressions of a sexp with regular expressions. Words fail me.