<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
is	O
a	O
dialect	O
of	O
the	O
Lisp	B-Language
programming	I-Language
language	I-Language
used	O
as	O
a	O
scripting	B-Language
language	I-Language
by	O
Emacs	B-Application
(	O
a	O
text	B-Application
editor	I-Application
family	O
most	O
commonly	O
associated	O
with	O
GNU	B-Application
Emacs	I-Application
and	O
XEmacs	B-Language
)	O
.	O
</s>
<s>
It	O
is	O
used	O
for	O
implementing	O
most	O
of	O
the	O
editing	O
functionality	O
built	O
into	O
Emacs	B-Application
,	O
the	O
remainder	O
being	O
written	O
in	O
C	B-Language
,	O
as	O
is	O
the	O
Lisp	B-Language
interpreter	B-Application
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
is	O
also	O
termed	O
Elisp	B-Operating_System
,	O
although	O
there	O
is	O
also	O
an	O
older	O
,	O
unrelated	O
Lisp	B-Language
dialect	O
with	O
that	O
name	O
.	O
</s>
<s>
Users	O
of	O
Emacs	B-Application
commonly	O
write	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
to	O
customize	O
and	O
extend	O
Emacs	B-Application
.	O
</s>
<s>
Other	O
options	O
include	O
the	O
Customize	O
feature	O
that	O
's	O
been	O
in	O
GNU	B-Application
Emacs	I-Application
since	O
version	O
20	O
.	O
</s>
<s>
Itself	O
written	O
in	O
Emacs	B-Operating_System
Lisp	I-Operating_System
,	O
Customize	O
provides	O
a	O
set	O
of	O
preferences	O
pages	O
allowing	O
the	O
user	O
to	O
set	O
options	O
and	O
preview	O
their	O
effect	O
in	O
the	O
running	O
Emacs	B-Application
session	O
.	O
</s>
<s>
When	O
the	O
user	O
saves	O
their	O
changes	O
,	O
Customize	O
simply	O
writes	O
the	O
necessary	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
to	O
the	O
user	O
's	O
config	B-Protocol
file	I-Protocol
,	O
which	O
can	O
be	O
set	O
to	O
a	O
special	O
file	O
that	O
only	O
Customize	O
uses	O
,	O
to	O
avoid	O
the	O
possibility	O
of	O
altering	O
the	O
user	O
's	O
own	O
file	O
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
can	O
also	O
function	O
as	O
a	O
scripting	B-Language
language	I-Language
,	O
much	O
like	O
the	O
Unix	B-Application
Bourne	B-Device
shell	I-Device
or	O
Perl	B-Language
,	O
by	O
calling	O
Emacs	B-Application
in	O
batch	O
mode	O
.	O
</s>
<s>
No	O
user	B-Application
interface	I-Application
is	O
presented	O
when	O
Emacs	B-Application
is	O
started	O
in	O
batch	O
mode	O
;	O
it	O
simply	O
executes	O
the	O
passed-in	O
script	O
and	O
exits	O
,	O
displaying	O
any	O
output	O
from	O
the	O
script	O
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
is	O
most	O
closely	O
related	O
to	O
Maclisp	B-Language
,	O
with	O
some	O
later	O
influence	O
from	O
Common	B-Language
Lisp	I-Language
.	O
</s>
<s>
It	O
supports	O
imperative	B-Application
and	O
functional	B-Language
programming	I-Language
methods	O
.	O
</s>
<s>
Richard	O
Stallman	O
chose	O
Lisp	B-Language
as	O
the	O
extension	B-Language
language	I-Language
for	O
his	O
rewrite	O
of	O
Emacs	B-Application
(	O
the	O
original	O
used	O
Text	B-Application
Editor	I-Application
and	I-Application
Corrector	I-Application
(	O
TECO	B-Application
)	O
as	O
its	O
extension	B-Language
language	I-Language
)	O
because	O
of	O
its	O
powerful	O
features	O
,	O
including	O
the	O
ability	O
to	O
treat	O
functions	O
as	O
data	O
.	O
</s>
<s>
Although	O
the	O
Common	B-Language
Lisp	I-Language
standard	O
had	O
yet	O
to	O
be	O
formulated	O
,	O
Scheme	B-Language
existed	O
at	O
the	O
time	O
Stallman	O
was	O
rewriting	O
Gosling	B-Operating_System
Emacs	I-Operating_System
into	O
GNU	B-Application
Emacs	I-Application
.	O
</s>
<s>
He	O
chose	O
not	O
to	O
use	O
it	O
because	O
of	O
its	O
comparatively	O
poor	O
performance	O
on	O
workstations	O
(	O
as	O
opposed	O
to	O
the	O
minicomputers	B-Architecture
that	O
were	O
Emacs	B-Application
 '	O
traditional	O
home	O
)	O
,	O
and	O
he	O
wanted	O
to	O
develop	O
a	O
dialect	O
which	O
he	O
thought	O
would	O
be	O
more	O
easily	O
optimized	O
.	O
</s>
<s>
The	O
Lisp	B-Language
dialect	O
used	O
in	O
Emacs	B-Application
differs	O
substantially	O
from	O
the	O
more	O
modern	O
Common	B-Language
Lisp	I-Language
and	O
Scheme	B-Language
dialects	O
used	O
for	O
applications	O
programming	O
.	O
</s>
<s>
A	O
prominent	O
characteristic	O
of	O
Emacs	B-Operating_System
Lisp	I-Operating_System
is	O
in	O
its	O
use	O
of	O
dynamic	O
rather	O
than	O
lexical	O
scope	B-Language
by	O
default	O
.	O
</s>
<s>
That	O
is	O
,	O
a	O
function	O
may	O
reference	O
local	O
variables	O
in	O
the	O
scope	B-Language
it	O
is	O
called	O
from	O
,	O
but	O
not	O
in	O
the	O
scope	B-Language
where	O
it	O
was	O
defined	O
.	O
</s>
<s>
Recently	O
,	O
there	O
has	O
been	O
an	O
ongoing	O
effort	O
to	O
update	O
code	O
to	O
use	O
lexical	O
scoping	B-Language
,	O
for	O
reasons	O
outlined	O
below	O
.	O
</s>
<s>
To	O
understand	O
the	O
logic	O
behind	O
Emacs	B-Operating_System
Lisp	I-Operating_System
,	O
it	O
is	O
important	O
to	O
remember	O
that	O
there	O
is	O
an	O
emphasis	O
on	O
providing	O
data	O
structures	O
and	O
features	O
specific	O
to	O
making	O
a	O
versatile	O
text	B-Application
editor	I-Application
over	O
implementing	O
a	O
general-purpose	O
programming	O
language	O
.	O
</s>
<s>
For	O
example	O
,	O
Emacs	B-Operating_System
Lisp	I-Operating_System
cannot	O
easily	O
read	O
a	O
file	O
a	O
line	O
at	O
a	O
time	O
—	O
the	O
entire	O
file	O
must	O
be	O
read	O
into	O
an	O
Emacs	B-Application
buffer	O
.	O
</s>
<s>
However	O
,	O
Emacs	B-Operating_System
Lisp	I-Operating_System
provides	O
many	O
features	O
for	O
navigating	O
and	O
modifying	O
buffer	O
text	O
at	O
a	O
sentence	O
,	O
paragraph	O
,	O
or	O
higher	O
syntactic	O
level	O
as	O
defined	O
by	O
modes	O
.	O
</s>
<s>
Here	O
follows	O
a	O
simple	O
example	O
of	O
an	O
Emacs	B-Application
extension	O
written	O
in	O
Emacs	B-Operating_System
Lisp	I-Operating_System
.	O
</s>
<s>
In	O
Emacs	B-Application
,	O
the	O
editing	O
area	O
can	O
be	O
split	O
into	O
separate	O
areas	O
called	O
windows	O
,	O
each	O
displaying	O
a	O
different	O
buffer	O
.	O
</s>
<s>
A	O
buffer	O
is	O
a	O
region	O
of	O
text	O
loaded	O
into	O
Emacs	B-Application
 '	O
memory	O
(	O
possibly	O
from	O
a	O
file	O
)	O
which	O
can	O
be	O
saved	O
into	O
a	O
text	O
document	O
.	O
</s>
<s>
Users	O
can	O
press	O
the	O
default	O
C-x	O
2	O
key	O
binding	O
to	O
open	O
a	O
new	O
window	O
.	O
</s>
<s>
This	O
runs	O
the	O
Emacs	B-Operating_System
Lisp	I-Operating_System
function	O
split-window-below	O
.	O
</s>
<s>
In	O
order	O
to	O
do	O
this	O
,	O
the	O
user	O
writes	O
the	O
following	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
,	O
in	O
either	O
an	O
existing	O
Emacs	B-Operating_System
Lisp	I-Operating_System
source	O
file	O
or	O
an	O
empty	O
Emacs	B-Application
buffer	O
:	O
</s>
<s>
The	O
second	O
statement	O
,	O
(	O
global-set-key	O
...	O
)	O
re-binds	O
the	O
key	O
sequence	O
"	O
C-x	O
2	O
"	O
to	O
the	O
new	O
function	O
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
advice	O
is	O
not	O
allowed	O
in	O
the	O
source	O
code	O
of	O
GNU	B-Application
Emacs	I-Application
,	O
but	O
if	O
a	O
user	O
wishes	O
,	O
the	O
advice	O
feature	O
can	O
be	O
used	O
in	O
their	O
code	O
to	O
reimplement	O
the	O
above	O
code	O
as	O
follows	O
:	O
</s>
<s>
Emacs	B-Application
24.4	O
replaces	O
this	O
defadvice	O
mechanism	O
with	O
advice-add	O
,	O
which	O
is	O
claimed	O
to	O
be	O
more	O
flexible	O
and	O
simpler	O
.	O
</s>
<s>
It	O
is	O
not	O
necessary	O
to	O
recompile	B-Language
,	O
restart	O
Emacs	B-Application
,	O
or	O
even	O
rehash	B-Algorithm
a	O
configuration	B-Protocol
file	I-Protocol
.	O
</s>
<s>
If	O
the	O
code	O
is	O
saved	O
into	O
an	O
Emacs	B-Application
init	O
file	O
,	O
then	O
Emacs	B-Application
will	O
load	O
the	O
extension	O
the	O
next	O
time	O
it	O
starts	O
.	O
</s>
<s>
Otherwise	O
,	O
the	O
changes	O
must	O
be	O
reevaluated	O
manually	O
when	O
Emacs	B-Application
is	O
restarted	O
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
is	O
stored	O
in	O
filesystems	B-Application
as	O
plain	O
text	O
files	O
,	O
by	O
convention	O
with	O
the	O
filename	O
suffix	O
"	O
.el	O
"	O
.	O
</s>
<s>
The	O
user	O
's	O
init	O
file	O
is	O
an	O
exception	O
,	O
often	O
appearing	O
as	O
"	O
.emacs	O
"	O
despite	O
being	O
evaluated	O
as	O
any	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
.	O
</s>
<s>
Since	O
the	O
mid-1990s	O
,	O
Emacs	B-Application
also	O
loads	O
~	O
/.emacs.el	O
and	O
~	O
/.emacs.d/init.el	O
.	O
</s>
<s>
Additionally	O
,	O
users	O
may	O
specify	O
any	O
file	O
to	O
load	O
as	O
a	O
config	B-Protocol
file	I-Protocol
on	O
the	O
command	O
line	O
,	O
or	O
explicitly	O
state	O
that	O
no	O
config	B-Protocol
file	I-Protocol
is	O
to	O
be	O
loaded	O
.	O
</s>
<s>
When	O
the	O
files	O
are	O
loaded	O
,	O
an	O
interpreter	B-Application
component	O
of	O
the	O
Emacs	B-Application
program	O
reads	O
and	O
parses	O
the	O
functions	O
and	O
variables	O
,	O
storing	O
them	O
in	O
memory	O
.	O
</s>
<s>
Functions	O
and	O
variables	O
can	O
be	O
freely	O
modified	O
and	O
redefined	O
without	O
restarting	O
the	O
editor	O
or	O
reloading	O
the	O
config	B-Protocol
file	I-Protocol
.	O
</s>
<s>
In	O
order	O
to	O
save	O
time	O
and	O
memory	O
space	O
,	O
much	O
of	O
the	O
functionality	O
of	O
Emacs	B-Application
loads	O
only	O
when	O
required	O
.	O
</s>
<s>
Each	O
set	O
of	O
optional	O
features	O
shipped	O
with	O
Emacs	B-Application
is	O
implemented	O
by	O
a	O
collection	O
of	O
Emacs	B-Application
code	O
called	O
a	O
package	B-Application
or	O
library	B-Library
.	O
</s>
<s>
For	O
example	O
,	O
there	O
is	O
a	O
library	B-Library
for	O
highlighting	O
keywords	O
in	O
program	O
source	O
code	O
,	O
and	O
a	O
library	B-Library
for	O
playing	O
the	O
game	O
of	O
Tetris	B-Device
.	O
</s>
<s>
Each	O
library	B-Library
is	O
implemented	O
using	O
one	O
or	O
more	O
Emacs	B-Operating_System
Lisp	I-Operating_System
source	O
files	O
.	O
</s>
<s>
Emacs	B-Application
developers	O
write	O
certain	O
functions	O
in	O
C	B-Language
.	O
These	O
are	O
primitives	O
,	O
also	O
termed	O
built-in	O
functions	O
or	O
subrs	O
.	O
</s>
<s>
Although	O
primitives	O
can	O
be	O
called	O
from	O
Lisp	B-Language
code	O
,	O
they	O
can	O
only	O
be	O
modified	O
by	O
editing	O
the	O
C	B-Language
source	O
files	O
and	O
recompiling	O
.	O
</s>
<s>
In	O
GNU	B-Application
Emacs	I-Application
,	O
primitives	O
are	O
not	O
available	O
as	O
external	O
libraries	O
;	O
they	O
are	O
part	O
of	O
the	O
Emacs	B-Application
executable	O
.	O
</s>
<s>
In	O
XEmacs	B-Language
,	O
runtime	O
loading	O
of	O
such	O
primitives	O
is	O
possible	O
,	O
using	O
the	O
operating	O
system	O
's	O
support	O
for	O
dynamic	B-Application
linking	I-Application
.	O
</s>
<s>
Functions	O
may	O
be	O
written	O
as	O
primitives	O
because	O
they	O
need	O
access	O
to	O
external	O
data	O
and	O
libraries	O
not	O
otherwise	O
available	O
from	O
Emacs	B-Operating_System
Lisp	I-Operating_System
,	O
or	O
because	O
they	O
are	O
called	O
often	O
enough	O
that	O
the	O
comparative	O
speed	O
of	O
C	B-Language
versus	O
Emacs	B-Operating_System
Lisp	I-Operating_System
makes	O
a	O
worthwhile	O
difference	O
.	O
</s>
<s>
However	O
,	O
because	O
errors	O
in	O
C	B-Language
code	O
can	O
easily	O
lead	O
to	O
segmentation	B-Error_Name
violations	I-Error_Name
or	O
to	O
more	O
subtle	O
bugs	O
,	O
which	O
crash	O
the	O
editor	O
,	O
and	O
because	O
writing	O
C	B-Language
code	O
that	O
interacts	O
correctly	O
with	O
the	O
Emacs	B-Operating_System
Lisp	I-Operating_System
garbage	B-General_Concept
collector	I-General_Concept
is	O
error-prone	O
,	O
the	O
number	O
of	O
functions	O
implemented	O
as	O
primitives	O
is	O
kept	O
to	O
a	O
necessary	O
minimum	O
.	O
</s>
<s>
Byte-compiling	O
can	O
make	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
execute	O
faster	O
.	O
</s>
<s>
Emacs	B-Application
contains	O
a	O
compiler	B-Language
which	O
can	O
translate	O
Emacs	B-Operating_System
Lisp	I-Operating_System
source	O
files	O
into	O
a	O
special	O
representation	O
termed	O
bytecode	O
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
bytecode	O
files	O
have	O
the	O
filename	O
suffix	O
"	O
.elc	O
"	O
.	O
</s>
<s>
The	O
standard	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
distributed	O
with	O
Emacs	B-Application
is	O
loaded	O
as	O
bytecode	O
,	O
although	O
the	O
matching	O
source	O
files	O
are	O
usually	O
provided	O
for	O
the	O
user	O
's	O
reference	O
as	O
well	O
.	O
</s>
<s>
User-supplied	O
extensions	O
are	O
typically	O
not	O
byte-compiled	O
,	O
as	O
they	O
are	O
neither	O
as	O
large	O
nor	O
as	O
computationally	O
intensive	O
.	O
</s>
<s>
Notably	O
,	O
the	O
"	O
cl-lib	O
"	O
package	B-Application
implements	O
a	O
fairly	O
large	O
subset	O
of	O
Common	B-Language
Lisp	I-Language
.	O
</s>
<s>
This	O
package	B-Application
replaces	O
an	O
earlier	O
"	O
cl	O
"	O
package	B-Application
,	O
which	O
would	O
overwrite	O
existing	O
Emacs	B-Operating_System
Lisp	I-Operating_System
function	O
definitions	O
with	O
ones	O
more	O
similar	O
to	O
those	O
found	O
in	O
Common	B-Language
Lisp	I-Language
.	O
</s>
<s>
The	O
"	O
cl-lib	O
"	O
package	B-Application
,	O
on	O
the	O
other	O
hand	O
,	O
follows	O
Emacs	B-Operating_System
Lisp	I-Operating_System
style	O
guidelines	O
more	O
closely	O
and	O
prefixes	O
each	O
function	O
and	O
macro	O
it	O
defines	O
with	O
"	O
cl-	O
"	O
(	O
e.g.	O
,	O
cl-defun	O
,	O
which	O
does	O
n't	O
conflict	O
with	O
the	O
name	O
of	O
the	O
built-in	O
defun	O
)	O
,	O
avoiding	O
the	O
unexpected	O
changes	O
in	O
behavior	O
that	O
could	O
occur	O
whenever	O
the	O
"	O
cl	O
"	O
package	B-Application
was	O
loaded	O
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
(	O
unlike	O
some	O
other	O
Lisp	B-Language
implementations	O
)	O
does	O
not	O
do	O
tail-call	B-Language
optimization	I-Language
.	O
</s>
<s>
Without	O
this	O
,	O
tail	B-Language
recursions	I-Language
can	O
eventually	O
lead	O
to	O
stack	B-Error_Name
overflow	I-Error_Name
.	O
</s>
<s>
The	O
apel	O
library	B-Library
aids	O
in	O
writing	O
portable	O
Emacs	B-Operating_System
Lisp	I-Operating_System
code	O
,	O
with	O
the	O
help	O
of	O
the	O
polysylabi	O
platform	O
bridge	O
.	O
</s>
<s>
Emacs	B-Operating_System
Lisp	I-Operating_System
is	O
a	O
Lisp-2	O
like	O
Common	B-Language
Lisp	I-Language
,	O
meaning	O
that	O
it	O
has	O
a	O
function	O
namespace	O
which	O
is	O
separate	O
from	O
the	O
namespace	O
it	O
uses	O
for	O
other	O
variables	O
.	O
</s>
<s>
Like	O
MacLisp	B-Language
,	O
Emacs	B-Operating_System
Lisp	I-Operating_System
uses	O
dynamic	O
scope	B-Language
,	O
offering	O
static	O
(	O
or	O
lexical	O
)	O
as	O
an	O
option	O
starting	O
from	O
version	O
24	O
.	O
</s>
<s>
Before	O
this	O
option	O
was	O
added	O
,	O
one	O
could	O
use	O
the	O
lexical-let	O
macro	O
from	O
the	O
(	O
now	O
deprecated	O
)	O
"	O
cl	O
"	O
package	B-Application
to	O
provide	O
effective	O
lexical	O
scope	B-Language
.	O
</s>
<s>
In	O
dynamic	O
scoping	B-Language
,	O
if	O
a	O
programmer	O
declares	O
a	O
variable	O
within	O
the	O
scope	B-Language
of	O
a	O
function	O
,	O
it	O
is	O
available	O
to	O
subroutines	O
called	O
from	O
within	O
that	O
function	O
.	O
</s>
<s>
Originally	O
,	O
this	O
was	O
intended	O
as	O
an	O
optimization	O
;	O
lexical	O
scoping	B-Language
was	O
still	O
uncommon	O
and	O
of	O
uncertain	O
performance	O
.	O
</s>
<s>
"	O
I	O
asked	O
RMS	O
when	O
he	O
was	O
implementing	O
emacs	B-Operating_System
lisp	I-Operating_System
why	O
it	O
was	O
dynamically	B-Language
scoped	I-Language
and	O
his	O
exact	O
reply	O
was	O
that	O
lexical	O
scope	B-Language
was	O
too	O
inefficient.	O
"	O
</s>
<s>
Dynamic	O
scoping	B-Language
was	O
also	O
meant	O
to	O
provide	O
greater	O
flexibility	O
for	O
user	O
customizations	O
.	O
</s>
<s>
However	O
,	O
dynamic	O
scoping	B-Language
has	O
several	O
disadvantages	O
.	O
</s>
<s>
Secondly	O
,	O
accessing	O
variables	O
under	O
dynamic	O
scoping	B-Language
is	O
generally	O
slower	O
than	O
under	O
lexical	O
scoping	B-Language
.	O
</s>
