1(defun require-if-exists (req &optional path)
2"Funct to require an argument if its accompanying path exists, adding that path to the load-path list if needed
3The path is specified relative to the base addons folder
5If the path is null, don't use a filename, relying on the filename being the same as the argument name
6Returns nil if the require fails"
8;; If a nil path, just require the pattern, ignoring errors
11 ;;(message "no path %s" req)
15 ;; If path exists, add to load path if not the base addons folder and require req
16 (setq path (concat "~/emacs/lisp/addons/" path))
17 ;; (message "path %s" path)
18 (if (not (equal (substring (file-name-directory path) -7) "addons/"))
19 (add-to-list 'load-path path))
20 ;; Get the filename, if there is one and it exists. Otherwise set fname to nil, to do a require based on require name
21 (if (and (not (file-directory-p path)) (file-exists-p path))
22 (setq fname (file-name-nondirectory path))
24;; require, ignoring on error
25;; (message "fname %s" fname)
26(setq reqqed (require req fname t))
29 ;; Return reqqed, as the import was a success
30 ;; (message "%s was required successfully" req)
33 ;; req failed, print a warning
34 (warn "Require failed for %s, using filename of %s and path of %s" req fname path))
37(provide 'de_require-if-exists)