help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very basic questions.


From: Tim X
Subject: Re: Very basic questions.
Date: Mon, 18 Sep 2006 15:42:52 +1000
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

"jronald" <followait@163.com> writes:

> "Colin S. Miller" <no-spam-thank-you@csmiller.demon.co.uk> 
> ??????:450bdfd3$0$75037$14726298@news.sunsite.dk...
>>>
>>> In runtime, how does "require" know where the feature list is? There is 
>>> only machine code then.
>>>
>> John,
>>
>> (require 'feature)
>> searches the paths listed in 'load-path',
>> this can be added to using (add-path).
>> It looks for a file called "feature.el" or "feature.elc".
>>
>>
> Do you mean that "provide" modifies the files, both .el and .elc? I just 
> can't imagine.
>
>> Emacs packages can either be in source-code,
>> which have an extension '.el', or be pre-compiled,
>> where they have the extension '.elc'.
>>
>> Pre-compiled packages run faster than packages dynamically
>> compiled from source.
>>
>> The pre-compiled emacs tends to come with its packages pre-compiled
>> as well, there will be sources for the packages where you got
>> emacs from.
>>
>> HTH,
>> Coin S. Miller
>>
>> -- 
>> Replace the obvious in my email address with the first three letters of 
>> the hostname to reply. 
>
>

John, 

I htink your over thinking this whole issue. Its very basic really. 

When you create an emacs lisp package, you add the following line.
Often it is added at the end of the file so that it doesn't run unless
the file loads correctly

(provide 'feature)

where 'feature is some symbol/name that reflects what is provided by
the code in that file. When this file is loaded, emacs will keep track
of this information and will know that this "feature" has been added.

The other side of the coin is "require', usually put at the top of a
file and indicates some feature or support library your code will
require, for example

(require 'feature)

When you load a file with this requirement into emacs, it will first
check to see if the feature has already been loaded (see C-h f
featurep for details of a predicate that can be used to determine if a
feature has been loaded). If the feature/library has not been loaded,
emacs will search the load-path for a file called feature.el or
feature.elc. If it finds one, it will load that file - note that that
file may also include more require statements, resulting in other
files being loaded. 

This whole mechanism is a bit similar to using C macros to ensure
header files are loaded and only loaded once. In a C header file
feature.h, you might have a line like

#define _FEATURE_H_ 

and in one of your other .c or .h files, you might have a line like

#ifndef _FEATURE_H_
#include "feature.h"
#endif

The issues regarding whether the files are byte compiled or just
interpreted are pretty much irrelevant and can be ignored with respect
to this mechanism. 

HTH

Tim


-- 
tcross (at) rapttech dot com dot au


reply via email to

[Prev in Thread] Current Thread [Next in Thread]