-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tex
3904 lines (3477 loc) · 195 KB
/
main.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[format=acmsmall,screen]{acmart}
%% \settopmatter{printfolios=true,printccs=false,printacmref=false}
\usepackage{booktabs} % For formal tables
\usepackage{longtable}
\usepackage{tabu}
\usepackage{alltt}
\usepackage{microtype}
\usepackage{fancyvrb}
\usepackage[utf8]{inputenc}
\usepackage{acmshepherd}
\usepackage{natbib}
\citestyle{acmauthoryear}
%% Paper history
%% Not sure where we got this from, but the HOPL editors ended asking it be
%% removed ;-)
%% \received{August 2018}
%% \received[Revised]{August 2019}
%% \received[Final]{March 2020}
%%
%% Preliminary Chinese translation by Yue Yi <includeyy123@gmail.com>:
%% https://egh0bww1.com/posts/2023-05-21-37-tr-evolution-of-emacs-lisp
%% While Richard prefers "Emacs Lisp" I find it unnecessarily verbose
%% and much prefer "Elisp" which is also very widely used.
\newcommand \Elisp {Emacs Lisp}
\newcommand \MAlign [1] {\begin{array}{@{}l@{}}#1\end{array}}
\newcommand \TAlign [1] {\begin{tabular}{@{}l@{}}#1\end{tabular}}
\newcommand \id[1] {\textrm{\textsl{#1}}}
\hyphenation{na-me-spa-ce}
%%% The following is specific to HOPL '20 and the paper
%%% 'Evolution of Emacs Lisp'
%%% by Stefan Monnier and Michael Sperber.
%%%
\setcopyright{rightsretained}
\acmPrice{}
\acmDOI{10.1145/3386324}
\acmYear{2020}
\copyrightyear{2020}
\acmSubmissionID{hopl20main-p16-p}
\acmJournal{PACMPL}
\acmVolume{4}
\acmNumber{HOPL}
\acmArticle{74}
\acmMonth{6}
%% Document starts
\begin{document}
%% Title portion. Note the short title for running heads
\title{Evolution of Emacs Lisp}
\author{Stefan Monnier}
\affiliation{%
\institution{Université de Montréal}
\streetaddress{C.P.\ 6128, succ.\ centre-ville}
\city{Montréal}
\state{QC}
\postcode{H3C 3J7}
\country{Canada}}
\email{monnier@iro.umontreal.ca}
\author{Michael Sperber}
\affiliation{%
\institution{Active Group GmbH}
\streetaddress{Hechinger Str.\ 12/1}
\city{Tübingen}
\country{Germany}
}
\email{sperber@deinprogramm.de}
\shepherd{Brent Hailpern, IBM Research, USA}
\begin{abstract}
While Emacs proponents largely agree that it is the world's greatest text editor, it is almost as much a Lisp machine disguised as an editor. Indeed, one of its chief appeals is that it is \emph{programmable} via its own programming language. Emacs Lisp is a Lisp in the classic tradition. In this article, we present the history of this language over its more than 30 years of evolution. Its core has remained remarkably stable since its inception in 1985, in large part to preserve compatibility with the many third-party packages providing a multitude of extensions. Still, Emacs Lisp has evolved and continues to do so.
Important aspects of Emacs Lisp have been shaped by concrete requirements of the editor it supports as well as implementation constraints. These requirements led to the choice of a Lisp dialect as Emacs's language in the first place, specifically its simplicity and dynamic nature: Loading additional Emacs packages or changing the ones in place occurs frequently, and having to restart the editor in order to re-compile or re-link the code would be unacceptable. Fulfilling this requirement in a more static language would have been difficult at best.
One of Lisp's chief characteristics is its malleability through its uniform syntax and the use of macros. This has allowed the language to evolve much more rapidly and substantively than the evolution of its core would suggest, by letting Emacs packages provide new surface syntax alongside new functions. In particular, Emacs Lisp can be customized to look much like Common Lisp, and additional packages provide multiple-dispatch object systems, legible regular expressions, programmable pattern-matching constructs, generalized variables, and more. Still, the core has also evolved, albeit slowly. Most notably, it acquired support for lexical scoping.
The timeline of Emacs Lisp development is closely tied to the projects and people who have shaped it over the years: We document Emacs Lisp history through its predecessors, Mocklisp and MacLisp, its early development up to the ``Emacs schism'' and the fork of Lucid Emacs, the development of XEmacs, and the subsequent rennaissance of Emacs development.
\end{abstract}
\begin{CCSXML}
<ccs2012>
<concept>
<concept_id>10003456.10003457.10003521.10003525</concept_id>
<concept_desc>Social and professional topics~History of programming languages</concept_desc>
<concept_significance>500</concept_significance>
</concept>
</ccs2012>
\end{CCSXML}
\ccsdesc[500]{Social and professional topics~History of programming languages}
%% \ccsdesc{Social and professional topics}
%% \ccsdesc{Professional topics}
%% \ccsdesc{History of computing}
%% \ccsdesc{History of programming languages}
%%
%% End generated code
%%
\keywords{History of programming languages, Lisp, Emacs Lisp}
\maketitle
\clearpage
\tableofcontents
%% \clearpage
\section{Introduction}
Emacs is a text editor originally developed by Richard Stallman, who is also
the founder of the Free Software Foundation (FSF) and who launched the GNU
Project.
\Elisp{} is the extension language of the Emacs text editor.
In this sense, it is just a side-project of Emacs and might be overlooked as
a programming language. But Emacs itself comes with more than a million
lines of \Elisp{} code, and yet more \Elisp{} is distributed separately from
Emacs in various Emacs Lisp Package Archives (ELPA). If you additionally
consider that the majority of Emacs users have likely written a few lines of
\Elisp{} in their configuration file, it is arguably one of the most widely
used dialects of Lisp.
%% FIXME: I feel like we should add something here, but not sure what.
\subsection{The Authors}
Neither of us was around when Emacs and \Elisp{} were designed, but we are
two researchers in programming languages with a keen interest and many
years of
experience in (X)Emacs and \Elisp{}, which made us well positioned to write
this article.
\smallskip
\noindent{Stefan Monnier} has been (and is still) a core contributor to
Emacs since 1999, was head maintainer from 2008 to 2015, and he supervised
student projects on the \Elisp{} implementation in Emacs.
\smallskip
\noindent{Michael Sperber} has been a core contributor to XEmacs since 1994.
Most of his work was done from 1995 to 2003, when he was a research
assistant at the University of Tübingen. Apart from his own work on
the XEmacs codebase, he supervised several student projects on the
\Elisp{} implementation in XEmacs, including a co-authored paper on the
analysis of dynamic scope~\cite{Neubauer01}.
\subsection{Paper Organization}
\Elisp{} has evolved in several strands and implementations over the
years, and thus its evolution did not happen along a single timeline.
Moreover, some aspects evolved over long periods of time. To avoid
excessive interleaving of those aspects, we have organized the
top-level structure of the paper into chronological eras. Within an
era, as a new topic is introduced, we usually follow that topic
chronologically to its conclusion, even if that means going beyond the
era where it started.
Emacs as we know it today itself started in 1984.
Section~\ref{sec:early-history} describes the driving motivation for
the early design and implementation of \Elisp. The following Section
\ref{sec:base-language-design} traces the evolution of the base
language design, and Section \ref{sec:base-language-implementation}
its implementation.
Development continued at a high pace until about 1991.
Around that time, its development slowed down and
was overtaken by Lucid Emacs, later renamed XEmacs, whose impact on
\Elisp{} we describe in Section~\ref{sec:xemacs}. Eventually,
development of Emacs picked up again, and both co-evolved until about
2007. We describe the relevant aspects of that evolution in
Section~\ref{sec:coevolution}. After 2007, XEmacs development slowed
down, and we describe this post-XEmacs period in
Section~\ref{sec:post-xemacs}, to finally conclude in
Section~\ref{sec:conclusion}.
\Elisp{} was re-implemented in several other projects outside this
succession. We briefly touch upon those projects in
Appendix~\ref{sec:alternative-implementations}.
Appendix~\ref{appendix:arceneaux} contains the transcript of an
interview with Joseph Arcenaux, the initial maintainer of Emacs 19.
%% \clearpage
\section{Emacs History}
\label{sec:emacs-history}
While in theory \Elisp{} exists independently from Emacs, its design,
implementation, and history are inextricably linked to that of Emacs, so we
present here a short overview of the important events in Emacs's life.
\subsection{Emacs's Early History}
\label{sec:emacs-early-history}
Emacs's original inception was as a set of macros and keybindings for the
TECO text editor. TECO was written by Dan Murphy starting in
1962~\cite{Murphy09}, then at the MIT AI lab, and featured a primitive
programming language. In the mid-1970s Richard
Stallman, then also at MIT, added to TECO a ``real-time edit mode'' (then
a novelty) that updated the display of the text being edited as typing
happened~\cite{MulticsEmacs1996}. This mode allowed mapping key strokes to little TECO programs, and
users would typically configure TECO to bind printing characters to
self-insert, and control characters to perform other tasks such as
navigation to other parts of the text via so-called \textit{macros}. Guy Steele
coordinated among the users, creating a common set of keybindings and macros, which
Richard Stallman evolved into the first version of
Emacs~\cite{EmacsLore,Seibel2009}. (``Emacs'' stands for ``editor macros.'')
Note that TECO and Emacs were not completely separate entities in the sense
that TECO's extension language was also Emacs's extension language and that
they evolved together, where TECO's extension language was regularly
extended to provide facilities then used by Emacs~\cite{Stallman2002}.
This original Emacs grew popular in the lab and soon started to be
reimplemented in various other systems. Several of those incarnations of
Emacs were written in Lisp, notably \emph{EINE} (recursive acronym for
``EINE Is Not Emacs'') on the Lisp Machine by Dan Weinreb, followed by
\emph{ZWEI} (for ``ZWEI was EINE Initially'') by Dan Weinreb and Mike
McMahon~\cite{Weinreb1979}, and \emph{Multics Emacs} by Bernie Greenberg in
1978~\cite{MulticsEmacs1996,Stallman2002} written in MacLisp~\cite{Moon1974,Pitman1983}.
Given Lisp's dynamic nature, it was only natural that those systems used
Lisp as their extension language.
\emph{Unix Emacs}, written by James Gosling in 1980/1981~\cite{Gosling1981}
and preserved in the history books as \emph{Gosling Emacs},
was implemented in C and it featured an extension
language called \emph{MLisp} or \emph{Mock Lisp}, which bears visual
resemblance to Lisp, but was a lesser member of the Lisp family in the
sense that it lacked data structures like \emph{cons} cells and was
generally too limited to be usable as an implementation language.
Richard Stallman, who had worked on
ZWEI~\cite{Stallman2018-personal}, liked the possibilities offered for
extending the editor by having Lisp be both the extension language and the
implementation language. But high-performance Lisp compilers were not
widely available, so he decided to write a (for him) second version of Emacs
which would use Lisp as its extension language, like Greenberg's Multics
Emacs, but where the implementation would be partly written in Lisp and
partly in C (including buffer manipulation primitives, the redisplay code,
and a Lisp interpreter) so as to be more widely available.
In 1984, Richard Stallman took Gosling Emacs as a starting point for this
endeavor, and began replacing
the Mock Lisp interpreter and data structures of Gosling Emacs
with a new interpreter for the language that is now \Elisp{}, adapting
internal data structures to those of
this \Elisp{} interpreter. At that time, Gosling Emacs was distributed
commercially by Unipress under the name \emph{Unipress Emacs}, and Unipress
ordered Richard Stallman to stop distributing his version of Emacs, which
forced him to replace or rewrite the rest of Emacs's code as well, such as
the code responsible for the redisplay. It also motivated him to invent the
GNU General Public License \cite{GPLHistory}, to try and ensure that users
of his code would never have to go through such an experience.
\subsection{Design Goals}
The initial design of \Elisp{} was motivated by the pervasive requirement of
\emph{extensibility}: users ``must be able to redefine each
character''~\cite{Stallman1981}. TECO and Gosling Emacs featured small
languages that were either too obscure or too weak to support this vision.
Consequently, Richard Stallman took inspiration from MacLisp, and \Elisp{}
started right from the beginning as a full-featured programming language with
powerful abstraction facilities, thus foregoing Greenspun's tenth
rule, a popular epigram on programming that came up in 1993: ``Any
sufficiently complicated C or Fortran program contains an
ad-hoc, informally-specified, bug-ridden, slow implementation of half of
Common Lisp.''~\cite{GreenspunsRule}
Moreover, Richard Stallman made the design of Emacs embody and showcase
the ideals of Free Software. For example, not only is it permitted to get
and modify the source code, but every effort is made to encourage the
end-user to do so. The resulting requirements had a profound influence on
the \Elisp{} language. Retrospectively, those
can be summarized as:
\begin{itemize}
\item The language should be accessible to a wide audience, so that as many
people as possible can adapt Emacs to their own needs, without being
dependent on the availability of someone with technical expertise.
For example, the
\emph{Introduction to Programming in Emacs Lisp}
tutorial~\citep{ElispIntro} targets users with no programming
experience. This has been a strong motivation to keep \Elisp{} on the
minimalist side and to resist incorporation of many Common Lisp features.
\item It should be easy for the end-user to find the relevant code in order
to modify Emacs's behavior. This has driven the development of elements
such as the \emph{docstrings} (Section~\ref{sec:docstrings}) and more generally the self-documenting
aspect of the language. It also imposes constraints on the evolution of
the language: the use of some facilities, such as \emph{advice}
(Section~\ref{sec:advice}), is
discouraged because it makes the code more opaque.
\item Emacs should be easily portable to as many platforms as possible.
This largely explains why \Elisp{} still runs in a simple byte-code interpreter.
\end{itemize}
\subsection{The Great Schism}
\label{sec:schism}
\label{sec:energize}
%% Note: I put "1988" here based on Richard Gabriel's email (quoted in
%% https://www.jwz.org/doc/lemacs.html) from 22 Jun 1992 where he says "4
%% years ago".
In 1988, Lucid Inc., a software development company founded by Richard
Gabriel and based in Menlo
Park, California, started a project called \emph{Energize}~\cite{GabrielEtAl1990,Gabriel-personal}.
Energize was to be a C/C++ integrated development environment based on
Emacs~\cite{GabrielLetter}. Lucid decided to use Emacs as the central
component of Energize. At the time, the current version of Emacs was
18, which was still essentially a textual application.
For Energize, Lucid needed a graphical user
interface and the ability to add a large number of annotations to
program source code.
Lucid hired Joseph Arcenaux,
the principal Emacs developer at that time, to add these features
for Lucid while continuing to work on the upcoming release of Emacs~19.
It soon became clear that the respective goals Lucid and the Free
Software Foundation had for Emacs~19 were incompatible,
and the required cooperation between Lucid and
the Free Software Foundation broke down
(Appendix~\ref{appendix:arceneaux}).
As a result, Lucid forked Emacs development, creating its own Emacs
variant \emph{Lucid Emacs}, whose primary developer and maintainer was
Jamie Zawinski.
In 1994, Lucid went bankrupt. Sun subsequently wanted to ship
Lucid Emacs with their operating system, and ended up financing some
of the continued development of Lucid Emacs, and effected a name
change to the current \emph{XEmacs}.
Sun eventually lost interest in XEmacs, which continued as an
open-source community effort.
\subsection{Timeline}
\newcommand \EDate [2] {#1} %Ignore second argument (day) to save space.
\begin{table}
\caption{Emacs development timeline}
\label{tab:timeline}
\begin{center}
\begin{tabular}{@{}l|l|l|l}
Date & Version & Maintainer & Notes \\ \hline
\EDate{1985-03}{-20}
& Emacs~13 & Richard Stallman & Earliest recorded release \\
\EDate{1985-07}{-15}
& Emacs~16.56 & Richard Stallman
& Oldest version still available \\
&&& Gosling Emacs code expunged\\
\EDate{1987-09}{-18} & Emacs~18.49 & Richard Stallman \\
1987 & Epoch & Alan M.\ Carroll & Forks from Emacs~18.49\\
\EDate{1988-12}{-14} & Epoch 1.0 & Alan M.\ Caroll, Simon Kaplan\\
\EDate{1989-08}{-23} & Emacs~18.55 & Richard Stallman \\
1990 & Emacs~19 & Joe Arcenaux & Forks from Emacs~18.55 \\
&&& Text properties, Sec.~\ref{sec:strings}\\
&&& \texttt{advice.el}, Sec.~\ref{sec:hooks} \\
1990-04 & Lucid Emacs 19.0 & Jamie Zawinski & Extents, Sec.~\ref{sec:strings} \\
\EDate{1990-08}{-27} & Epoch 4.0 & Marc Andreesen \\
\EDate{1992-10}{-31} & Emacs~18.59 & Richard Stallman
& Last release of Emacs~18\\
\EDate{1993-05}{-22} & Emacs~19.7 beta & Jim Blandy & First public beta of Emacs~19 \\
&&& \texttt{lambda} macro, Sec.~\ref{sec:lambda}\\
\EDate{1993-05}{-27} & Emacs~19.8 beta & Jim Blandy \\
\EDate{1993-09}{-06} & Lucid Emacs 19.8 & Jamie Zawinski
& 4-bit tags, Sec~\ref{sec:data-representation} \\
&&& Merged Epoch and Emacs~19.8 \\
\EDate{1994-05}{-17} & Emacs~19.23 beta & Richard Stallman \\
\EDate{1994-05}{-27} & Lucid Emacs 19.10 & Jamie Zawinski \\
\EDate{1994-09}{-13} & XEmacs~19.11 & Chuck Thompson, Ben Wing \\
\EDate{1994-11}{-01} & Emacs~19.28 & Richard Stallman
& Proper backquote, Sec.~\ref{sec:backquote} \\
&&& First real release of Emacs~19\\
\EDate{1995-06}{-19} & Emacs~19.29 & Richard Stallman
& 3-bit tags, Sec.~\ref{sec:data-representation} \\
1995 & XEmacs~20 & Steve Baur & Work on MULE support begins\\
\EDate{1995-09}{-01} & XEmacs~19.13 & Chuck Thompson, Ben Wing
& Merged Emacs~19.30\\
%% \EDate{1995-11}{-24} & Emacs~19.30 & Richard Stallman \\
%% \EDate{1996-05}{-25} & Emacs~19.31 & Richard Stallman \\
\EDate{1996-08}{-21} & Emacs~19.34 & Richard Stallman
& Last release of Emacs~19 \\
\EDate{1997-02}{-09} & XEmacs~20.0 & Steve Baur & Custom library,
Sec.~\ref{sec:custom} \\
\EDate{1997-03}{-26} & XEmacs~19.15 & Steve Baur \\
\EDate{1997-09}{-17} & Emacs 20.1 & Richard Stallman
& First release with MULE \\
\EDate{1997-10}{-31} & XEmacs~19.16 & Steve Baur \\
\EDate{1998-02}{-28} & XEmacs~20.4 & Steve Baur
& First stable release with MULE\\ % support
&&& Packages shipped separately\\
\EDate{1998-07}{-12} & XEmacs~21.0 & Steve Baur & 1-bit tags \\
\EDate{2001-04}{-16} & XEmacs~21.4 & Stephen Turnbull \\
\EDate{2001-10}{-20} & Emacs 21.1 & Gerd Möllmann
& New redisplay engine \\
%% \EDate{2002-03}{-18} & Emacs 21.2 & Gerd Möllmann
%% & Last version with MLisp support, Sec.~\ref{sec:mock-lisp}\\
\EDate{2007-06}{-01} & Emacs 22.1 & Richard Stallman
& Last bits of Mock Lisp removed \\
%% Chong and I started as maintainers in February 2008.
\EDate{2009-07}{-28} & Emacs 23.1 & Chong Yidong, Stefan Monnier
& Unicode internally, Sec.~\ref{sec:unicode} \\
\EDate{2012-06}{-10} & Emacs 24.1 & Chong Yidong, Stefan Monnier
& Lexical scoping, Sec.~\ref{sec:lexical-scoping}
%% FIXME: No room on the same line, not sure it's worth using an
%% extra line for it:
%% ; Pcase, Sec.~\ref{sec:pcase}
\\
\EDate{2013-03}{-10} & Emacs 24.3 & Chong Yidong, Stefan Monnier
& CL-Lib, Sec.~\ref{sec:cl-lib} \\
\EDate{2014-10}{-20} & Emacs 24.4 & Chong Yidong, Stefan Monnier
& \texttt{nadvice.el}, Sec.~\ref{sec:hooks}\\
\EDate{2016-09}{-17} & Emacs 25.1 & John Wiegley, Eli Zaretskii \\
\EDate{2018-05}{-28} & Emacs 26.1 & John Wiegley, Eli Zaretskii
& Records, Sec.~\ref{sec:structures} \\ & & & Threads, Sec~\ref{sec:concurrency}
%% \EDate{20??-??}{-??} & Emacs 27 &
%% & Old-style backquotes removed, Sec.~\ref{sec:backquote} \\
\end{tabular}
\end{center}
\end{table}
Table~\ref{tab:timeline} contains a timeline of significant milestones in
the development of Emacs and Lucid Emacs/XEmacs. It also includes a few
milestones from \textit{Epoch}, a predecessor to Lucid Emacs that had
support for multiple windows.
For the time until 2007, the timeline in this table borrows much
from Jamie Zawinski's timeline~\cite{JWZTimeline}.
According to the \texttt{etc/NEWS.1-17} file, Emacs versions counted from
1.1 to 1.12 and then switched to 13 which was the first version announced
publicly on usenet.
\subsection{Development Model}
This section describes the development organization of Emacs and Lucid
Emacs/XEmacs, respectively.
\paragraph{Emacs}
Emacs is a Free Software project, developed by a loosely connected
set of volunteers doing it mostly in their spare time, and several of them
do not consider themselves computer professionals. Development is not
really organized, in the sense that volunteers work on what they find
appealing rather than follow some agreed upon plan, and the overall
direction of evolution is in effect controlled by the \emph{head
maintainer(s)} by accepting or rejecting contributions, and via discussions in
mailing lists. At times, the Free Software Foundation paid the
maintainer a salary, but this is not currently the case.
Richard Stallman was the original maintainer and still participates. Even
though several other people have been official maintainers at various points
in time, he always acted as a ``default maintainer'' when no one wanted to
step up and he has followed Emacs's development very closely even when he
was not officially the maintainer. Also, as Richard Stallman is
the founder of the Free Software Foundation, Emacs is part of the FSF's GNU
project and is linked to the FSF by its use of FSF's resources to host
the code and own the copyright. The link with the FSF is of course
particularly strong because of Stallman's role in Emacs.
The organization of Emacs's development is not really codified, but in
practice the role of the maintainer is a balancing act between the desire to
maintain a sane code base, to promote Free Software, to be attractive to its
users, and to encourage contributions. There is also more structure to the
organization: maintenance is really shared among a handful of people who
earned each other's respect by the weight of their past contributions and
who can then make more or less any change they like to the code, and accept
or reject external contributions, as long as nobody complains. In case of
disagreement between those core contributors the maintainer has the final
say. This structure probably appeared around 1991 and until 2000 was
embodied in the fact that the core contributors were members of a private
\emph{emacs-core} mailing-list and were the only ones with direct access to
the code. Since late 2000, when the CVS server became public and the
\emph{emacs-core} private mailing-list was replaced by the public
\emph{emacs-devel} mailing-list, this has become much more blurry:
technically, more than a hundred contributors have direct write access to
the code now and nowhere is it ever written or said which of those is or
is not considered a core contributor at any given point it time. Instead the
system functions by self-regulation: every time someone installs a change
without prior permission, someone else may or may not complain about the
change's quality, which can lead to requiring further changes or even
a complete revert, so over time contributors learn to judge on their own
what makes a change acceptable.
\paragraph{Lucid Emacs/XEmacs}
Lucid Emacs was initially managed by the respective maintainers, who
integrated patches sent by contributors, and published tarballs for
releases on ftp sites.
This changed when Steve Baur took over as maintainer in 1996: He
imported the source code into a publically accessible CVS repository on
the SourceForge platform for open-source software. Steve Baur then
established a \textit{review board} whose members received commit
access to the repository, and whose job was to review and apply
patches via a special mailing list, \texttt{xemacs-patches}, which
exists to this day.
For XEmacs~19.15, Steve Baur also split off many \Elisp{} packages
into a separate repository, with the ability to manage and update the
packages independently from the core releases, and installed
individual maintainers for many of these packages.
%%
In 2007, Michael Sperber migrated the source code from CVS to
Mercurial, hosted on the Bitbucket platform.
\section{Early Language Design} % -1992?
\label{sec:early-history}
The design of \Elisp{} was based on the past experiences with the extension
languages of TECO, ZWEI, Gosling Emacs, and Multics Emacs.
Arguably, the strongest influence for the language itself was MacLisp while
the design of the editing primitives was influenced by Gosling Emacs's
MLisp.
\subsection{Mock Lisp}
\label{sec:mock-lisp}
Gosling Emacs, arguably the immediate predecessor of today's Emacs,
featured an extension language called \emph{MLisp} or \emph{Mock Lisp},
which bears visual resemblance to \Elisp{}. MLisp featured function
definitions via \texttt{defun}, as well as many built-in functions (such as
\texttt{eolp}, \texttt{forward-character}, \texttt{save-excursion}) whose
names survive in \Elisp{}. Emacs even contained some limited
back\-ward-compatibility support for MLisp until Emacs~22 in 2007.
MLisp was a quite limited language: It lacked cons cells and lists.
MLisp did have dynamic scoping and local variables, but a peculiar
mechanism for passing arguments: There were no named
parameters. Instead, a program would invoke the \texttt{arg}
function: For example, \texttt{(arg 1)} would access the first
argument. Moreover, argument expressions were essentially evaluated
in a call-by-name fashion by \texttt{arg}, and evaluation happened in
the dynamic environment of the callee.
With the design of the primitives, Richard Stallman adopted MLisp's
basic approach~\cite{Stallman2018-personal}, diverging from ZWEI.
ZWEI primitives would always take explicit arguments to specify on what
text to operate. Here is what a ZWEI function might have looked
like that inserted a string surrounded by parentheses:
%
\begin{verbatim}
(DEFUN INSERT-PARENS (BP STRING)
(LET* ((BP1 (INSERT BP "("))
(BP2 (INSERT BP1 STRING))
(BP3 (INSERT BP2 ")")))
BP3))
\end{verbatim}
%
The \texttt{BP} parameter is for the location at which the insertion
is to take place. \texttt{INSERT-PARENS} calls the primitive
\texttt{INSERT} function three times; \texttt{INSERT} returns a new
location, after the insertion, which gets threaded through the
subsequent \texttt{INSERT} calls and finally returned.
The Mock Lisp primitives differed from those of ZWEI in that they operated
at the current \emph{point} (the current ``cursor position''), as was the
case in TECO. Here is the \texttt{in-parens} function from the Gosling
Emacs manual~\cite{Gosling1981}:
%
\begin{verbatim}
(defun
(in-parens
(insert-string "(")
(insert-string (arg 1 "String to insert? "))
(insert-string ")")
))
\end{verbatim}
%
Stallman, who had worked on ZWEI, found ZWEI's approach clumsy and
adopted MLisp's approach for Emacs.
\subsection{Maclisp}
MacLisp was a Lisp dialect developed at MIT's Project MAC in the early
1970s, which was named for its conceptual relationship with ``Multiple
Access Computers'' and ``Machine-Aided Cognition''~\cite{Pitman1983}.
It was developed for use in artificial intelligence research and
related fields. It descended from Lisp 1.5, albeit with many changes~\cite{Moon1974}.
MacLisp ran on the DEC PDP-10 series machines under various operating
systems, and on the Honeywell 6180/6880 under Multics.
\noindent
Maclisp had all basic properties associated with Lisp today~\cite{Moon1974}:
%
\begin{itemize}
\item Structure is defined through parentheses and prefix notation.
\item Code forms have an internal representation as
\textit{S-expressions}, which print the same as the code, a property called
homoiconicity.
\item There is an \texttt{eval} function that evaluates an expression
represented as an S-expression.
\item The basic data structure is \textit{cons}. A cons pairs two
objects, with the first component named \textit{car}, the second
\textit{cdr}. Conses are used to implement singly-linked
\textit{lists}, where a special \textit{nil} value indicates the end
of the list. Conses are mutable.
\item A special \textit{symbol} data type represents identifiers in
S-expressions, but is also often used to represent enumerations,
status values etc.
\item It is possible to define new compound data types via the
\texttt{defstruct} form.
\item The language has first-class functions via the \texttt{lambda}
form.
\item MacLisp also has an \texttt{apply} function that will apply a
function to a list of arguments, converting between argument lists
and regular lists.
\item Local variables are bound \textit{dynamically} rather than
lexically: A local variable occurence refers to the last active
binding at run time, rather than the lexically enclosing binding.
\item The language has \textit{macros} that introduce new syntactic
forms; macros are essentially defined as functions on the S-expressions
representing code.
\end{itemize}
%
Here is a simple example of a MacLisp function definition from the
original manual~\cite{Moon1974}:
%
\begin{verbatim}
(defun assoc (x y)
(cond
((null y) nil)
((equal x (caar y)) (car y))
((assoc x (cdr y)))))
\end{verbatim}
%
This looks for an entry \texttt{x} in a list of conses \texttt{y}, an
association list. The \texttt{cond} is a branching construct with
a list of branches. The first one has condition \texttt{(null y)}, which
checks whether the \texttt{y} list is empty. If it is, \texttt{assoc}
returns \texttt{nil}. The second branch has condition \texttt{(equal
x (caar y))}, which checks whether \texttt{x} is equal to the car of the
first element of \texttt{y}. (The \texttt{caar} function takes the
``car of the car.'') In that case, it returns the first cons, whose
car is equal to x. Finally, if none of the cases matched,
\texttt{assoc} recurs on the cdr of \texttt{y}.
This function definition works in \Elisp{} unchanged to this day.
\section{Base Language Design}
\label{sec:base-language-design}
When designing \Elisp{}, Richard Stallman was not really interested in the
design of a new language, but had more pragmatic concerns: he
wanted to have a real Lisp system but was constrained by the need for the
implementation to be simple and lightweight enough to fit the limited
resources of the machines of the time. So the base language of \Elisp{} is
a straightforward subset of MacLisp~\cite{Moon1974,Pitman1983} and Lisp
Machine Lisp~\cite{WeinrebMoon1981}.
Contrary to its siblings Common Lisp and Scheme, which both strive for
a kind of completeness and consistency (although in different ways),
Richard Stallman has
had no such desire for \Elisp, even occasionally reminding contributors
not to ``propose new Emacs features for mere completeness'
sake.''~\cite{RMS-completeness}.
Most basic special forms are identical to MacLisp: \texttt{defun},
\texttt{defvar}, \texttt{defmacro}, \texttt{let}, \texttt{let*},
\texttt{cond}, \texttt{if}, \texttt{function}, \texttt{catch}, \texttt{throw},
\texttt{unwind-protect}. So are basic data structures: symbols,
\texttt{nil}, cons cells, and many familiar Lisp functions.
\Elisp{} also supports arrays, using a subset (specifically only uni-dimensional
arrays) of the primitives offered in Lisp Machine Lisp, which happens to
also be a subset of the Common Lisp primitives, rather than Maclisp's
approach of accessing arrays as if they were functions.
% FIXME: elaborate on arrays?
Like MacLisp, \Elisp{} offered only
dynamic scoping of variables. Also like MacLisp, \Elisp{} was (and still is) a Lisp-2
language~\cite{SteeleGabriel1993}, which means that the namespaces for
functions and ``ordinary values'' are separate, and to call a function bound
to a variable, a program must use \texttt{funcall}. Also, symbols can be
used as function values.
Unlike MacLisp, the original \Elisp{} featured no way to define new
data types and
%%
some specialized control structures were missing in the original
\Elisp{}, among them the \texttt{do} loop construct, and the
accompanying \texttt{return} and \texttt{go} forms for non-local
control transfer. This reduced Emacs's memory footprint
to make it work on Unix systems with one megabyte of memory~\cite{Stallman2018-personal}.
This section discusses the notable choices in language design such as
the choice of dynamic scoping, notable differences from and additions to
MacLisp, and language features designed to satisfy requirements of the
Emacs editor.
\subsection{Symbols and Dynamic Scoping}
\label{sec:symbols}
Like any Lisp, \Elisp{} has always had a symbol data type: The expression
\texttt{'emacs} yields a symbol named \texttt{emacs}. One way to look
at symbols is that they are immutable strings with a fast equality
check and usually fast hashing. This makes them suitable for values
representing enumerations or options. Another is that symbols can
represent names in an \Elisp{} program. Symbols are thus a key
feature to make \Elisp{} \textit{homoiconic}, meaning that each
\Elisp{} form can be represented by a data structure called an
\textit{S-expression} that prints out the same as the form.
\Elisp{} took from MacLisp the choice of dynamic scoping implemented using
\emph{shallow binding}, where the
latest binding of a variable is simply stored in the \emph{value slot}
of the heap object that represents the symbol, resulting in simple and efficient
variable lookups and let-bindings. Symbols can be used to refer to
variables. In particular, the \texttt{set} function, which performs
assignment, accepts a symbol naming the variable as its argument.
A symbol, again borrowing from
MacLisp, also carries a \textit{property list}, essentially a key-value
mapping stored in a list.
Richard
Stallman chose dynamic scoping despite the fact that the two major emerging
Lisps at the time---Common Lisp and Scheme---were moving to lexical
scoping~\cite{CLtL1,R2RS}.
Richard Stallman chose dynamic scoping to meet extensibility
requirements in Emacs~\cite{Stallman1981}. The Emacs code base uses
variables to hold configuration options. These configuration
options often need to be modified temporarily, restoring the original
value after a piece of code has run. Here is an example:
%
\begin{verbatim}
(defun dired-smart-shell-command (command &optional output-buffer error-buffer)
"Like function `shell-command', but in the current Virtual Dired directory."
(interactive ...)
(let ((default-directory (or (and (eq major-mode 'dired-mode)
(dired-current-directory))
default-directory)))
(shell-command command output-buffer error-buffer)))
\end{verbatim}
%
This function invokes \texttt{shell-command} to execute an external
command. The working directory of that command is determined by the
\texttt{default-directory} variable: In Dired mode (a built-in file
manager) that directory needs to be the directory the cursor is at.
So in this case, the \texttt{let} is used to temporarily bind
\texttt{default-directory} to the return value of
\texttt{(dired-current-directory)}.
It would in principle be
possible to structure the code base to pass configuration options
explicitly, but this would make the code verbose, and require changing
many function signatures once a new configuration option gets added to
the system.
Richard Stallman considered the possibility of having an alternate
scope rule early, but deemed the availability of dynamic scoping
necessary~\cite{Stallman1981}. More recently, lexical scoping has
been added as an option to Emacs (Section~\ref{sec:lexical-scoping}).
\subsection{Backquote}
\label{sec:backquote}
Quasiquotation is a classic feature of Lisp readers, including
MacLisp's~\cite{Bawden1999}: It allows creating nested list
structures---particularly those representing code---via templates.
Quasiquotation is a more general mechanism than \texttt{quote} for
creating nested list structure without using constructors explicitly:
\texttt{quote} is usually introduced via \verb|'| where the \emph{reader}
translates \verb|'|\textsl{SEXP} to \texttt{(quote }\textsl{SEXP}\texttt{)},
and this expression evaluates to the value \textsl{SEXP}.
For example:
%
\begin{verbatim}
'(a (b c d) c)
\end{verbatim}
%
evalutes to a list whose first element is the symbol \texttt{a}, the
second a list consisting of elements \texttt{b}, \texttt{c}, and
\texttt{d}, and whose third element is \texttt{c}. It does so in constant
time, by always returning the same value already present in the source code
returned by the \emph{reader}.
Quasiquotation is usually introduced via \verb|`|,
where the reader translates \verb|`|\textit{exp} to
\texttt{(quasiquote }\textit{exp}\texttt{)} (nevertheless, the mechanism is
often referred to as \textit{backquote}). Quasiquotation operates like
\verb|'|, but a \texttt{quasiquote} form may contain \texttt{,} and \texttt{,@}
subforms, which insert or splice the value of expressions into the
result.
Here is a \texttt{quasiquote} example:
%
\begin{verbatim}
`(do ((i 0 (+ 1 i)))
((>= i ,array-size))
(aset ,array-name i ,init-val))
\end{verbatim}
%
This might expand into the following \texttt{quasiquote}-less code:
%
\begin{verbatim}
(list 'do '((i 0 (+ 1 i)))
(list (list '>= 'i array-size))
(list 'aset array-name 'i init-val))
\end{verbatim}
%
\Elisp{} did not until 1994 include the reader syntax for
quasiquotation.
Instead, the special forms that came with quasiquotation---backquote
(\verb|`|), unquote (\verb|,|) and unquote-splicing (\verb|,@|) were
simply the names of special forms. Thus, what is usually written as:
%%
\begin{verbatim}
`(a b ,c)
\end{verbatim}
%%
was written in early \Elisp{} as:
%%
\begin{verbatim}
(` (a b (, c)))
\end{verbatim}
%%
The releases of Emacs~19.28 and XEmacs~19.12 in 1994 finally added the
proper reader support to generate the latter version from the former.
The extended reader had to rely on a heuristic for the translation, however,
%% FIXME: Using ` within a \texttt gives a different quote than using \verb !!
because \verb|(`a)| is valid in both syntaxes but means different
things: It could either denote an old-style backquote expression
(i.e., \verb|(` a)| in the old notation) or a single-element list containing
the new-style backquoted symbol \texttt{a} (i.e., \verb|((` a))| in the old
notation).
%% Stefan: I can't see when/where it was actually declared obsolete,
%% but it clearly was made obsolete by the introduction of the new syntax.
So the old format, though obsolete, was still supported, and the
new format was recognized only in some cases; more specifically the new
unquote was recognized only within a new backquote, and the new
backquote was recognized only if it occurred within a new backquote or
if it did not immediately follow an open parenthesis.
Seeing how uses of old-style backquotes were not going away by themselves,
in 2007
Emacs~22.2 introduced explicit tests and warnings to bring attention to uses
of old-style backquotes, while still keeping the actual behavior unchanged.
Then in 2012 with the release of Emacs~24.1, the behavior was changed so
that the old format is recognized only if it follows a parenthesis and is
followed by a space. The main motivation for this change was the
introduction of the \texttt{pcase} macro (Section~\ref{sec:pcase}) where
patterns can also use the
backquote syntax and are commonly placed right after a parenthesis so they
were otherwise mistaken for an old-style backquote syntax.
Support for the old-style syntax has been preserved for many years because
it was used very widely and removing it would have caused regressions for
too many users relying on outdated or unmaintained third-party packages.
But over the years, users have slowly updated or stopped using those
packages, so this syntax is finally removed in Emacs~27.
\subsection{Lambda}
\label{sec:lambda}
In Lisp dialects, anonymous functions are usually the result of
\texttt{lambda} expressions. Here is an anomymous function that adds
1 to a number:
%
\begin{verbatim}
(lambda (x) (+ x 1))
\end{verbatim}
%
Interestingly, \texttt{lambda} was not originally a keyword of the
\Elisp{} language (unlike in MacLisp). But anonymous
function \emph{values} could be lists of the following form:
%
\begin{verbatim}
(lambda (..ARGS..) ..BODY..)
\end{verbatim}
%
The use of dynamic scope made it unnecessary to create closures, so it was
possible to write these anonymous functions in source code using the
pre-existing quoted Lisp literal mechanism:
%
\begin{verbatim}
'(lambda (..ARGS..) ..BODY..)
\end{verbatim}
%
This \emph{expression} evaluates to a nested list structure whose first
element happens to be the \texttt{lambda} symbol. When a program calls
\texttt{funcall} passing such a value, \texttt{funcall} would
recognize the list structure as representing a \texttt{lambda}
expression and invoke the interpreter on it.
The extra quote character was a small price to pay for a slightly simpler
Lisp implementation. But the byte-code compiler is not allowed to compile the
content of such a quoted list except in those rare cases where it can
determine that it will be used only as a function, so \Elisp{} acquired in
version 1.4 the \texttt{function} special form (also imported from MacLisp)
for the alternative notation:
%
\begin{verbatim}
(function (lambda (..ARGS..) ..BODY..))
\end{verbatim}
%
In 1992, \texttt{lambda} was added as a macro, early during the
development of Emacs~19. The macro simply returns the list representation
wrapped inside the \texttt{function} special form:
\begin{verbatim}
(defmacro lambda (&rest args)
(list 'function (cons 'lambda args)))
\end{verbatim}
It is not completely
clear why it took so long to introduce this simple macro, but it was likely
due to the fact that anonymous functions were not used very often and that
they were mostly used in places that were not very sensitive to performance.
While the \texttt{lambda} macro has made \texttt{(lambda ..)} superior to
\texttt{'(lambda ..)} for almost
30 years now, instances of this practice can still be found, thanks to the
power of copy\&paste, in many code snippets posted on the web, users'
configuration files, and third party \Elisp{} packages, even though it
prevents byte-code compilation of the function's body.
Somewhat relatedly, only in 1993 did Lucid Emacs 19.8 import the
\verb|#'...| reader shorthand for \texttt{(function ...)} from MacLisp.
Emacs followed suit the year after.
\subsection{Macros}
\label{sec:macros}
An important feature of \Elisp{} is the ability to define new syntactic
forms via \texttt{defmacro}, as shown in the previous example. This is
important because it means not only Emacs but also \Elisp{} itself can be
extended to adapt it to the user's needs. This ability has had a profound
impact on the evolution of the language, letting it develop independently
from the core constructs.
\Elisp{} macros were taken directly from MacLisp and also correspond very
closely to the \texttt{defmacro} of Common Lisp. This form of macro
definition is well known to suffer from a lack of hygiene, a problem that
has been addressed in more recent macro systems like that of Scheme.
While the most obvious consequences of the lack of hygiene are traditionally
circumvented in \Elisp{} using \texttt{gensym}, there has never been any
attempt or even discussion about addressing this problem of hygiene in
a more general way. Maybe this is in part due to the heavy reliance on
dynamic scoping which already forces the programmer to be careful with the
choice of identifiers.
\subsection{Structures}
\label{sec:structures}
MacLisp offers the \texttt{defstruct} form for defining new data
types called \textit{structures}. Here is an example which defines a
\texttt{KONS} data type, which has two fields called \texttt{KAR} and \texttt{KDR}:
%
\begin{verbatim}
(DEFSTRUCT KONS KAR KDR)
\end{verbatim}
%
This form would define four functions, \texttt{MAKE-KONS}, \texttt{KAR},
\texttt{KDR}, and \texttt{ALTER-KONS}. A program could create a
\texttt{KONS} structure with \texttt{MAKE-KONS}:
%
\begin{verbatim}
(MAKE-KONS KDR 3 KAR 4)
\end{verbatim}
%
\texttt{KAR} and \texttt{KDR} can then be used to access the
respective field contents of a \texttt{KONS} structure, and
\texttt{ALTER-KONS} to mutate these contents.
\Elisp{} never had \texttt{defstruct} as a primitive form. This
reflects a more general design philosophy, which uses the existing
data types of pairs and vectors for even complicated data structures
such as keymaps (Section~\ref{sec:keymaps}).
Instead, a Common-Lisp-compatible \texttt{defstruct} has been part of the
\texttt{cl.el} package (Section~\ref{sec:cl-lib}). Use of
\texttt{defstruct} in \Elisp{} code began to be commonplace only around
2010. Originally \texttt{defstruct} used plain vectors under the hood to represent the
structures, making it impossible to reliably distinguish them from vectors,
but in 2013 Lars Brinkhoff added the \emph{record} data type to make
structures distinct from vectors
(Section~\ref{sec:actual-objects}). Making \texttt{defstruct} use this new
data type introduced some backward incompatibilities, so the change lived in
a separate branch for four years during which various mitigation strategies
were developed, until it was finally included in Emacs~26.1.
\subsection{Non-Local Exits}
\label{sec:non-local-exits}
Very early on, \Elisp{} featured primitives to handle
non-local exits. It inherited the \texttt{catch}, \texttt{throw}, and
\texttt{unwind-protect} primitives from MacLisp. Here is an example:
%
\begin{verbatim}
(defun outer ()
(catch 'marker
(inner)))
(defun inner ()
...
(if x
(throw 'marker 'catch-value))
...)