Previous: , Up: Loading   [Index]


11.2 Provide and Require

These work in terms of named features. A feature is loaded the first time another program asks for it by name. A feature name is a symbol that stands for a collection of functions, variables, etc. The file that defines the functions, variabes, etc. should provide the feature. Another program that uses them may ensure they are defined by requiring the feature. This loads the file of definitions if it has not been loaded yet.

To require the presence of a feature, call require with the feature name as argument. require looks in the global variable features to see whether the desired feature has been provide already. If not, it loads the feature from the appropriate file. This file should call provide at the top level to add the feature to features.

Features are normally named after the files that provide them, so that require need not be given the file name.

Function: provide feature &optional subfeatures
FEATURE

a symbol that accounces that FEATURE is a feature of the current Emacs, e.g., it is loaded into the current Emacs session, and its facilities are or will be available for other Lisp programs. provide ensures that FEATURE is added to the front of the variable features if it is not already there. If it has not already been added, the provide calls any eval-after-load code waiting for it.

SUBFEATURES

a list of symbols listing particular subfeatures supported in this version of FEATURE.

RETURN VALUE

FEATURE is returned.

Function: require feature &optional filename noerror
FEATURE

a symbol representing a set of code and variables to load into the current Emacs. If FEATURE is not a member of the list held by the variable features, tested by featurep, then load it from FILENAME. If FILENAME is omitted, the printname of FEATURE is used as the file name, and load will try to laod this name, with an added suffixe (require). The directories in load-path are searched.

FILENAME

if given, then load the feature from the file identified by FILENAME.

NOERROR

if non-nil, return nil if the file is not found instead of signalling an error.

RETURN VALUE

the return value is FEATURE.

Function: featurep feature &optional subfeature
FEATURE

the symbol to check. This function returns t if FEATURE has already been provided in the current Emacs session.

RETURN VALUE

Boolean t if FEATURE has alreayd been provided.

Variable: features

The value of this variable is list of symbols that are the features loaded in the current Emacs session, put there by calls to provide.


Previous: Load Functions, Up: Loading   [Index]