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
|
[[!meta title="Gypsum: my clone of Emacs and ELisp written in Scheme"]]
[[!meta copyright="Copyright © 2024 Ramin Honary"]]
[[!inline pages="internal(2024/info/gypsum-nav)" raw="yes"]]
<!-- Initially generated with emacsconf-publish-talk-page and then left alone for manual editing -->
<!-- You can manually edit this file to update the abstract, add links, etc. --->
# Gypsum: my clone of Emacs and ELisp written in Scheme
Ramin Honary (he/him)
- E-mail: <mailto:ramin.honary@gmail.com>
- ActivityPub: @ramin_hal9001@fe.disroot.org
- Website: <https://tilde.town/~ramin_hal9001>
[[!inline pages="internal(2024/info/gypsum-before)" raw="yes"]]
## Slides
### Introduction
1. Ramin Honary
- Emacs enthusiast since 2017
- Software developer (full stack)
- I love Haskell, Scheme, functional programming
- Started learning Scheme about 2 years ago
2. My project: an Emacs Clone
- Tentative name: "Gypsum"
- Its not a great name, open to suggestions.
### Goal: to Clone **Emacs Lisp**
- Many clones already:
- Edwin, Jed, jEdit, Jove, Lem, MG, Yi, Zile
- These only clone the key bindings, not Elisp
- Only XEmacs (a fork of GNU Emacs) provided an alternative Emacs Lisp
### Most people don't use Emacs for the keybindings
- Anecodtal, but yes really.
- Use Emacs because of the power of Emacs Lisp
- Emacs is as powerful as a system shell
- A good language is what makes it powerful
### Goal: use R7RS Standard Scheme
- I want it to work on a many Scheme implementations
- Guile is the reference implementation
- (more about this later)
### Goal: able to run any `init.el`
- Should be able to use `init.el` without significant changes
- Many invest significant time in their configs
- Suddenly not having your config is disruptive
- Such an Emacs clone would be more useful
### Why do this?
- I personally like Scheme's minimalism.
- Use Scheme as more than just an academic language.
- Seems to be a lot of interest in a project like this.
- Talk of "Guile Emacs" for about 30 years
### A long history of Guile Emacs (1/3)
- **Early 90s**: Initial discussion between RMS, Tom Lord,
Aubrey Jaffer, begin work on replacing Emacs Lisp with Scheme.
- **1999--2009**: Ken Raeburn's [Guile-Based Emacs](https://www.mit.edu/~raeburn/guilemacs/).
(My project is similar.)
> "*This project that I (Ken Raeburn) have started is for converting*
> *GNU Emacs to use Guile as its programming language. Support for*
> *Emacs Lisp will continue to exist, of course, but it may be*
> *through translation and/or interpretation; the Lisp engine itself*
> *may no longer be the core of the program.*"
### A long history of Guile Emacs (2/3)
- **2010**: Andy Wingo and Ludovic Courtes
take maintainership of Guile project.
- **2009--2011**: Emacs Lisp interpreter implemented in Guile.
Still ships with Guile.
- **2011**: Guile 2.0 is released
- **2011--2015**: Robin Templeton's GSoC project.
(Is presenting later today!)
### A long history of Guile Emacs (3/3)
- **2020**: Vasilij Schneidermann published an overview called
"[The State of Emacs Lisp on Guile](https://emacsninja.com/posts/state-of-emacs-lisp-on-guile.html)".
- **2020 to present**: Guile Emacs is dead? Andrea Corallo, GCC Emacs,
JIT-compiler for Emacs Lisp based on "libgccjit", brings into
question any need for combining Guile with Emacs.
### Demo
### GUI is barely working
- I have almost no experience with Gtk or GObject Introspection
- Hard to debug, crashes at C-level produce no stack traces
- Using GDB requires rebuilding all of Gtk, GIO, GLib, etc.
### Emacs Lisp parser based on Guile Emacs Lisp
- Foked the Guile Emacs Lisp implementation for easier development
- Have already submitted a patch to the parser upstream
### Emacs Lisp interpter is barely working
- Implementing my own interpreter in portable Scheme
- Monadic pattern matcher
### Can parse but not interpret "`subr.el`"
- "`subr.el`" is the first ELisp file run by Emacs
- A good way to determine what to work on first
### A call for help
### Latest Emacs has **1,393** built-in functions
- I could never implement that many functions alone
- Probably not all are required to create a useful editor
### My job is to make contributing easy
- Document the build and test process
- Document the system architecture
- Prioritize which built-in functions are most essential
- Find low-hanging fruit, use as means to teach others
### The work for which I will take responsibility
- Clone enough Elisp to be able to run ERT tests
- Then use GNU Emacs's own regression tests to test patches
- Make sure there is a usable GUI
- (Someday?) be able to contribute a patch from within
### Quick architectural overview
### The editor is based in Scheme, not Emacs Lisp
- Config, scripting, packages all done in Scheme
- Use of Emacs Lisp for scripting not encouraged
- Should still be able to run your `init.el`
- Ideally should be able to run ELPA packages
### Difference with Robin Templeton's project
- Guile-Emacs links Guile runtime into Emacs
- Not a Scheme application
- An IDE for Schemers
### Emacs Lisp is an "environment"
- "Environments" are a feature of Scheme
- Scheme procedures can be called from Emacs Lisp
- Scheme state can be mutated by Emacs Lisp
- (See "`./gypsum/elisp-eval.scm`", "`new-env`")
### "Functional Lenses"
- Because R7RS does not standardize MOP (not even in "large")
- Inspired by Haskell
- Composes getters and setters
- Single source file, easy to port
- Ported to 3 other Schemes
### A lot of work went into keymaps data structure
- Keybindings are an important part of Emacs
- Had to do this well from very beginning
- Keybindings work correctly in demo
### A lot of work went into separating GUI from Editor logic
- "Parameters" are a feature of Scheme
- Platform-specific APIs are always parameterized
- Windowing and widgets
- Translate key events to bindings
- Evaluating Scheme expressions
- Text buffering and rendering
- (See "`./gypsum/editor-impl.scm`")
### Monadic pattern matching
- Simpler, more portable
- (Not as feature-rich)
- Easier than porting SRFI-241 ("Match") to Guile
- No relation to SRFI-247 ("Syntatic Monads")
- You can still use pattern matching
### Monad pattern matching
Example program
(define push-stack (put-with cons))
(define collatz
(many
push-stack
(either
(try (check (λ (n) (<= n 1)))
(success))
(try (check odd?)
(next (λ (n) (+ 1 (* 3 n)))))
(try (check even?)
(next (λ (n) (quotient n 2))))
(fail "not an integer")
)))
### Conclusion
- I am just getting the ball rolling
- Helping others contribute is my top priority
- ActivityPub :: `ramin_hal9001@fe.disroot.org`
- E-mail :: <span class="spurious-link"
target="ramin.honary@gmail.com">*ramin.honary@gmail.com*</span>
- Homepage :: <https://tilde.town/~ramin_hal9001>
- Codeberg :: <https://codeberg.org/ramin_hal9001>
- This presentation :: <https://emacsconf.org/2024/talks/gypsum/>
## Original presentation proposal
I would like to demonstrate an Emacs clone I have been
writing in Guile Scheme for the past year, which I am
tentatively calling "Gypsum". Unlike other editors which
only clone the Emacs keybindings (Edwin, Jed, jEdit, Jove,
Lem, MG, Yi, Zile), I hope my Emacs clone will also fully
clone the Emacs Lisp programming language well enough that
many of the packages in ELPA, Non-GNU ELPA, and perhaps even
MELPA, can be used in "Gypsum" without any modification. I
would also like to talk a little bit about the how I am
implementing it (the software architecture), and invite
others to contribute.
I think my project is of interest to many Emacs users
because, firstly, I have personally spoken with a relatively
large number of people who have expressed interest in making
Emacs programmable in Scheme. Secondly, there is a good
amount of prior art for Scheme implementations of
Emacs. There are even builds of Emacs that link to Guile
which provides a "scheme-eval" built-in function that
translates between Elisp data types and Scheme data
types. The Guile compiler itself ships with an Emacs Lisp
compiler as well, although it does not provide enough of
Emacs's built-in functions to be of much use.
So by using Guile, we can make use of a lot of the prior
art, in fact I am currently using the tokenizer and reader
used in Guile's built-in Elisp interpreter to implement
"Gypsum's" Elisp interpreter. That said, I have gone out of
my way to make my code fully R7RS compliant, so I hope I can
port it to other Scheme implementations like MIT Scheme,
Gambit, Stklos, and perhaps Chez Scheme with Gwen Weinholt's
R7-to-R6RS translator. I consider the Guile version of
Gypsum to be the reference implementation of what I hope
will become a fully cross-platform programming language and
text editor written in portable R7RS Scheme.
The reference implementation of "Gypsum" is a GUI
application based on Gtk using a library called
"Guile-GI". Guile-GI uses the GObject Introspection
framework to automatically generate Scheme language bindings
to libraries like Gtk and Glib which are written in the C
programming language. There is not yet any terminal-emulator
version of "Gypsum."
The next step of the project will be to implement enough of
Elisp that we can run tests written in the Emacs Regression
Testing (ERT) framework. We can then incorporate the
original GNU Emacs regression test suite into Gypsum. Any
new API added to Gypsum Elisp will most likely already have
regression tests we can use to make sure it is working in a
way that is compatible with GNU Emacs Lisp. I would like to
make it as easy as possible for people to contribute to this
project, and having a list of APIs to be implemented each
with a set of regression tests the APIs are expected to
pass, is a very good way to do that.
About the speaker:
My name is Ramin Honary, I have been a professional software
engineer of 16 years, lately mostly doing full-stack
software development. I have always been fascinated with
programming languages, and especially functional languages
like Lisp and Haskell. I have been using Emacs
since 2017. But lately it is with Scheme that I have been
spending most of my free time. I am only a Scheme
programming enthusiast, I am not involved with Scheme
professionally.
You may also like another talk by this speaker:
[EmacsConf - 2022 - talks - Build a Zettelkasten with the Hyperbole Rolodex](https://emacsconf.org/2022/talks/rolodex/)
[[!inline pages="internal(2024/info/gypsum-after)" raw="yes"]]
[[!inline pages="internal(2024/info/gypsum-nav)" raw="yes"]]
|