+;; FIXME: Check through major mode conventions again.
+
+;; FIXME: Add proper ";;;###autoload" comments.
+
+;; FIXME: When 24.1 is common place remove use of `lexical-let' and put "-*-
+;; lexical-binding: t -*-" in the first line.
+
+;; FIXME: Use `testcover'.
+
+;; FIXME: The adornment classification often called `ado' should be a
+;; `defstruct'.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Support for `testcover'
+
+(when (and (boundp 'testcover-1value-functions)
+ (boundp 'testcover-compose-functions))
+ ;; Below `lambda' is used in a loop with varying parameters and is thus not
+ ;; 1valued.
+ (setq testcover-1value-functions
+ (delq 'lambda testcover-1value-functions))
+ (add-to-list 'testcover-compose-functions 'lambda))
+
+(defun rst-testcover-defcustom ()
+ "Remove all customized variables from `testcover-module-constants'.
+This seems to be a bug in `testcover': `defcustom' variables are
+considered constants. Revert it with this function after each `defcustom'."
+ (when (boundp 'testcover-module-constants)
+ (setq testcover-module-constants
+ (delq nil
+ (mapcar
+ (lambda (sym)
+ (if (not (plist-member (symbol-plist sym) 'standard-value))
+ sym))
+ testcover-module-constants)))))
+
+(defun rst-testcover-add-compose (fun)
+ "Add FUN to `testcover-compose-functions'."
+ (when (boundp 'testcover-compose-functions)
+ (add-to-list 'testcover-compose-functions fun)))
+
+(defun rst-testcover-add-1value (fun)
+ "Add FUN to `testcover-1value-functions'."
+ (when (boundp 'testcover-1value-functions)
+ (add-to-list 'testcover-1value-functions fun)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Common Lisp stuff
+
+;; Only use of macros is allowed - may be replaced by `cl-lib' some time.
+(eval-when-compile
+ (require 'cl))
+
+;; Redefine some functions from `cl.el' in a proper namespace until they may be
+;; used from there.
+
+(defun rst-signum (x)
+ "Return 1 if X is positive, -1 if negative, 0 if zero."
+ (cond
+ ((> x 0) 1)
+ ((< x 0) -1)
+ (t 0)))
+
+(defun rst-some (seq &optional pred)
+ "Return non-nil if any element of SEQ yields non-nil when PRED is applied.
+Apply PRED to each element of list SEQ until the first non-nil
+result is yielded and return this result. PRED defaults to
+`identity'."
+ (unless pred
+ (setq pred 'identity))
+ (catch 'rst-some
+ (dolist (elem seq)
+ (let ((r (funcall pred elem)))
+ (when r
+ (throw 'rst-some r))))))
+
+(defun rst-position-if (pred seq)
+ "Return position of first element satisfying PRED in list SEQ or nil."
+ (catch 'rst-position-if
+ (let ((i 0))
+ (dolist (elem seq)
+ (when (funcall pred elem)
+ (throw 'rst-position-if i))
+ (incf i)))))
+
+(defun rst-position (elem seq)
+ "Return position of ELEM in list SEQ or nil.
+Comparison done with `equal'."
+ ;; Create a closure containing `elem' so the `lambda' always sees our
+ ;; parameter instead of an `elem' which may be in dynamic scope at the time
+ ;; of execution of the `lambda'.
+ (lexical-let ((elem elem))
+ (rst-position-if (function (lambda (e)
+ (equal elem e)))
+ seq)))
+
+;; FIXME: Embed complicated `defconst's in `eval-when-compile'.