dot-emacs: New functions: library-exists-p and maybe-autoload
authorMark Wooding <mdw@distorted.org.uk>
Thu, 23 Mar 2006 14:06:01 +0000 (14:06 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 23 Mar 2006 14:06:01 +0000 (14:06 +0000)
library-exists-p decides whether an Emacs library is present.
maybe-autoload sets up an autoload if a library exists.

dot-emacs.el

index 9899ef9..75e021b 100644 (file)
                             (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)))
+
 ;; --- Splitting windows ---
 
 (defconst mdw-scrollbar-width (if window-system 6 1)