changelog shortlog tags changeset files revisions annotate raw

de_require-if-exists.el

changeset 66: 5b737eefe5ea
parent:3238b8870351
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
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
4
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"
7
8;; If a nil path, just require the pattern, ignoring errors
9(if (not path)
10 (progn
11 ;;(message "no path %s" req)
12 (setq fname nil))
13
14 ;; Not a null path
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))
23 (setq fname nil)))
24;; require, ignoring on error
25;; (message "fname %s" fname)
26(setq reqqed (require req fname t))
27(if reqqed
28 (progn
29 ;; Return reqqed, as the import was a success
30 ;; (message "%s was required successfully" req)
31
32 reqqed)
33 ;; req failed, print a warning
34 (warn "Require failed for %s, using filename of %s and path of %s" req fname path))
35)
36
37(provide 'de_require-if-exists)