SXEmacs Lisp has several interfaces for loading. For example,
autoload creates a placeholder object for a function in a file;
trying to call the autoloading function loads the file to get the
function's real definition (see Autoload). require loads a
file if it isn't already loaded (see Named Features). Ultimately, all
these facilities call the load function to do the work.
This function finds and opens a file of Lisp code, evaluates all the forms in it, and closes the file.
To find the file,
loadfirst looks for a file named filename.elc, that is, for a file whose name is filename with ‘.elc’ appended. If such a file exists, it is loaded. If there is no file by that name, thenloadlooks for a file named filename.el. If that file exists, it is loaded. Finally, if neither of those names is found,loadlooks for a file named filename with nothing appended, and loads it if it exists. (Theloadfunction is not clever about looking at filename. In the perverse case of a file named foo.el.el, evaluation of(load "foo.el")will indeed find it.)If the optional argument nosuffix is non-
nil, then the suffixes ‘.elc’ and ‘.el’ are not tried. In this case, you must specify the precise file name you want.If filename is a relative file name, such as foo or baz/foo.bar,
loadsearches for the file using the variableload-path. It appends filename to each of the directories listed inload-path, and loads the first file it finds whose name matches. The current default directory is tried only if it is specified inload-path, wherenilstands for the default directory.loadtries all three possible suffixes in the first directory inload-path, then all three suffixes in the second directory, and so on.If you get a warning that foo.elc is older than foo.el, it means you should consider recompiling foo.el. See Byte Compilation.
Messages like ‘Loading foo...’ and ‘Loading foo...done’ appear in the echo area during loading unless nomessage is non-
nil.Any unhandled errors while loading a file terminate loading. If the load was done for the sake of
autoload, any function definitions made during the loading are undone.If
loadcan't find the file to load, then normally it signals the errorfile-error(with ‘Cannot open load file filename’). But if missing-ok is non-nil, thenloadjust returnsnil.You can use the variable
load-read-functionto specify a function forloadto use instead ofreadfor reading expressions. See below.
loadreturnstif the file loads successfully.
The value of this variable is a list of directories to search when loading files with
load. Each element is a string (which must be a directory name) ornil(which stands for the current working directory). The value ofload-pathis initialized from the environment variableEMACSLOADPATH, if that exists; otherwise its default value is specified in emacs/src/paths.h when SXEmacs is built.The syntax of
EMACSLOADPATHis the same as used forPATH; ‘:’ (or ‘;’, according to the operating system) separates directory names, and ‘.’ is used for the current default directory. Here is an example of how to set yourEMACSLOADPATHvariable from acsh.login file:setenv EMACSLOADPATH .:/user/bil/emacs:/usr/lib/emacs/lispHere is how to set it using
sh:export EMACSLOADPATH EMACSLOADPATH=.:/user/bil/emacs:/usr/local/lib/emacs/lispHere is an example of code you can place in a init.el file to add several directories to the front of your default
load-path:(setq load-path (append (list nil "/user/bil/emacs" "/usr/local/lisplib" "~/emacs") load-path))In this example, the path searches the current working directory first, followed then by the /user/bil/emacs directory, the /usr/local/lisplib directory, and the ~/emacs directory, which are then followed by the standard directories for Lisp code.
The command line options ‘-l’ or ‘-load’ specify a Lisp library to load as part of SXEmacs startup.
Dumping SXEmacs uses a special value of
load-path. If the value ofload-pathat the end of dumping is unchanged (that is, still the same special value), the dumped SXEmacs switches to the ordinaryload-pathvalue when it starts up, as described above. But ifload-pathhas any other value at the end of dumping, that value is used for execution of the dumped SXEmacs also.Therefore, if you want to change
load-pathtemporarily for loading a few libraries in site-init.el or site-load.el, you should bindload-pathlocally withletaround the calls toload.
This function searches for a file in the same way that
loaddoes, and returns the file found (if any). (In fact,loaduses this function to search throughload-path.) It searches for filename through path-list, expanded by one of the optional suffixes (string of suffixes separated by ‘:’s), checking for access mode (0|1|2|4 = exists|executable|writable|readable), default readable.
locate-filekeeps hash tables of the directories it searches through, in order to speed things up. It tries valiantly to not get confused in the face of a changing and unpredictable environment, but can occasionally get tripped up. In this case, you will have to calllocate-file-clear-hashingto get it back on track. See that function for details.
This function clears the hash records for the specified list of directories.
locate-fileuses a hashing scheme to speed lookup, and will correctly track the following environmental changes:
- changes of any sort to the list of directories to be searched.
- addition and deletion of non-shadowing files (see below) from the directories in the list.
- byte-compilation of a .el file into a .elc file.
locate-filewill primarily get confused if you add a file that shadows (i.e. has the same name as) another file further down in the directory list. In this case, you must calllocate-file-clear-hashing.
This variable is non-
nilif SXEmacs is in the process of loading a file, and it isnilotherwise.
This variable specifies an alternate expression-reading function for
loadandeval-regionto use instead ofread. The function should accept one argument, just asreaddoes.Normally, the variable's value is
nil, which means those functions should useread.
This variable specifies whether
loadshould check whether the source is newer than the binary. If this variable is true, then when a ‘.elc’ file is being loaded and the corresponding ‘.el’ is newer, a warning message will be printed. The default isnil, but it is bound totduring the initial loadup.
This variable specifies whether
loadshould warn when loading a ‘.el’ file instead of an ‘.elc’. If this variable is true, then whenloadis called with a filename without an extension, and the ‘.elc’ version doesn't exist but the ‘.el’ version does, then a message will be printed. If an explicit extension is passed toload, no warning will be printed. The default isnil, but it is bound totduring the initial loadup.
This variable specifies whether
loadshould ignore ‘.elc’ files when a suffix is not given. This is normally used only to bootstrap the ‘.elc’ files when building SXEmacs, when you use the command ‘make all-elc’. (This forces the ‘.el’ versions to be loaded in the process of compiling those same files, so that existing out-of-date ‘.elc’ files do not make it mess things up.)
To learn how load is used to build SXEmacs,
see Building SXEmacs.