dot-emacs: New functions: library-exists-p and maybe-autoload
[profile] / 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)