Emacs multi-file develop/run-from-of-source routines
The rational behind module is to be able to write small Emacs functions or modules in a larger multi-file Emacs package and facilitate running from the source tree without having to "install" the code or fiddle with evil load-path's . See my NYC Lisp talk for more background on this.
The latest version is at http://github.com/rocky/emacs-load-relative
__FILE__ returns the file name that that the calling program is running. If you are eval'ing a buffer then the file name of that buffer is used. The name was selected to be analogous to the name used in C, Perl, and Ruby.
For an common example of using this, see How to Insert Demo Code into an Emacs Lisp Module.
load-relative loads an Emacs Lisp file relative to another
(presumably currently running) Emacs Lisp file. For example suppose
you have Emacs Lisp files
bar.el in the same directory.
To load Emacs Lisp file
bar.el from inside Emacs lisp file
(require 'load-relative) (load-relative "baz")
That load-relative line could above have also been written as:
(load-relative "baz.el") # if you want to exclude any byte-compiled files
Use require-relative if you want to require the file instead of load'ing it:
The above not only does a require on
'baz, but makes sure you get
that from the same file as you would have if you had issued
Use require-relative-list when you have a list of files you want to require. To require-relative them in one shot:
(require-relative-list '("dbgr-init" "dbgr-fringe"))
The macro provide-me saves you the trouble of adding a symbol after provide, by using the file basename (without directory or file extension) as the name of the thing you want to provide. Using this forces the provide names to be the same as the filename, but I consider that a good thing.
provide-me also takes an optional string which will be prepended to the provide name. This is useful if you have a multi-file package and want the files to bue prefaced with the name of the package.
Assume your package foo and contains simply file
inside that file is the same thing as writing:
foo.el is part of a larger package called bar. Then if
this is the same as writing:
The function find-file-noselect-relative provides a way of accessing resources which are located relative to the currently running Emacs lisp file. This is probably most useful when running Emacs as a scripting engine for batch processing or with tests cases.
The macro with-relative-file runs in a buffer with the contents of the given relative file.
(with-relative-file "README.md" (buffer-substring))