]> code.delx.au - gnu-emacs-elpa/blob - load-relative.el
Merge branch 'master' of git@github.com:rocky/emacs-load-relative
[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 (if (listp file-or-list)
29 (mapcar (lambda(relative-file)
30 (load (relative-expand-file-name relative-file symbol)))
31 file-or-list)
32 (load (relative-expand-file-name file-or-list symbol))))
33
34 (defun relative-expand-file-name(relative-file symbol)
35 (let ((prefix (file-name-directory (or (__FILE__ symbol) "./"))))
36 <<<<<<< HEAD:load-relative.el
37 (expand-file-name (concat prefix relative-file))))
38
39 (defun require-relative (relative-file symbol)
40 "`require' an Emacs Lisp file relative to some other currently loaded Emacs
41 Lisp file."
42 (let ((require-string-name
43 (file-name-sans-extension
44 (file-name-nondirectory relative-file))))
45 (require (intern require-string-name)
46 (relative-expand-file-name relative-file symbol))))
47 =======
48 (if (listp file-or-list)
49 (mapcar (lambda(file) (load-relative-internal prefix file))
50 file-or-list)
51 (load-relative-internal prefix file-or-list))))
52
53 (defun load-relative-internal(directory-prefix file-suffix)
54 "Concatenate DIRECTORY-PREFIX with FILE-SUFFIX and call `load' on the
55 expanded file name (via `expand-file-name'"
56 (load (expand-file-name (concat directory-prefix file-suffix))))
57
58 (defsubst load-relative-and-provide(file-or-list symbol)
59 "Run `provide' on symbol and then run `load-relative' on
60 FILE-OR-LIST."
61 (provide symbol)
62 (load-relative file-or-list symbol))
63 >>>>>>> 4784bc30c4e554d102ce1b0d0b733e414a6b9b8c:load-relative.el