]> code.delx.au - gnu-emacs-elpa/blob - load-relative.el
Allow load-relative to accept a list of strings of files to load.
[gnu-emacs-elpa] / load-relative.el
1 (provide 'load-relative)
2 (defun __FILE__ (symbol)
3 "Return the string name of file of the currently running Emacs Lisp program,
4 or nil.
5
6 SYMBOL should be some symbol defined in the file, but it is not
7 used if Emacs is currently running `load' of a file. The simplest
8 thing to do is call `provide' prior to this and use the value
9 given for that for SYMBOL. For example:
10 (provide 'something)
11 (__FILE__ 'something)
12 "
13 (cond
14 (load-file-name)
15 ((symbol-file symbol))
16 (t nil)))
17
18 (defun load-relative (file-or-list symbol)
19 "Load an Emacs Lisp file relative to some other currently loaded Emacs
20 Lisp file.
21
22 FILE-OR-LIST is Emacs Lisp either a string or a list of strings
23 containing files that you want to loaded. SYMBOL should a symbol
24 defined another Emacs Lisp file that you want FILE loaded relative
25 to. If this is called inside a `load', then SYMBOL is ignored and
26 `load-file-name' is used instead."
27
28 (let ((prefix (file-name-directory (or (__FILE__ symbol) "./"))))
29 (if (listp file-or-list)
30 (mapcar (lambda(file) (load (concat prefix file))) file-or-list)
31 (load (concat prefix file-or-list)))))
32