+;; --- Configuration reading ---
+
+(defvar mdw-config nil)
+(defun mdw-config (sym)
+ "Read the configuration variable named SYM."
+ (unless mdw-config
+ (setq mdw-config (with-temp-buffer
+ (insert-file-contents "~/.mdw.conf")
+ (replace-regexp "^[ \t]*\\(#.*\\|\\)\n" ""
+ nil (point-min) (point-max))
+ (replace-regexp (concat "^[ \t]*"
+ "\\([-a-zA-Z0-9_.]*\\)"
+ "[ \t]*=[ \t]*"
+ "\\(.*[^ \t\n]\\|\\)"
+ "[ \t]**\\(\n\\|$\\)")
+ "(\\1 . \"\\2\") "
+ nil (point-min) (point-max))
+ (car (read-from-string
+ (concat "(" (buffer-string) ")"))))))
+ (cdr (assq sym mdw-config)))
+
+;; --- Is an Emacs library available? ---
+
+(defun library-exists-p (name)
+ "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load
+path. The non-nil value is the filename we found for the library."
+ (let ((path load-path) elt (foundp nil))
+ (while (and path (not foundp))
+ (setq elt (car path))
+ (setq path (cdr path))
+ (setq foundp (or (let ((file (concat elt "/" name ".elc")))
+ (and (file-exists-p file) file))
+ (let ((file (concat elt "/" name ".el")))
+ (and (file-exists-p file) file)))))
+ foundp))
+
+(defun maybe-autoload (symbol file &optional docstring interactivep type)
+ "Set an autoload if the file actually exists."
+ (and (library-exists-p file)
+ (autoload symbol file docstring interactivep type)))
+