Back to the talks Previous by time: Managing writing project metadata with org-mode Next by time: The Future of Org Track: Development - Watch

Gypsum: my clone of Emacs and ELisp written in Scheme

Ramin Honary (he/him)

The following image shows where the talk is in the schedule for Sat 2024-12-07. Solid lines show talks with Q&A via BigBlueButton. Dashed lines show talks with Q&A via IRC or Etherpad.

Format: 25-min talk; Q&A: BigBlueButton conference room https://media.emacsconf.org/2024/current/bbb-gypsum.html
Discuss on IRC: #emacsconf
Status: Ready to stream

Times in different time zones:
Saturday, Dec 7 2024, ~10:00 AM - 10:20 AM EST (US/Eastern)
which is the same as:
Saturday, Dec 7 2024, ~9:00 AM - 9:20 AM CST (US/Central)
Saturday, Dec 7 2024, ~8:00 AM - 8:20 AM MST (US/Mountain)
Saturday, Dec 7 2024, ~7:00 AM - 7:20 AM PST (US/Pacific)
Saturday, Dec 7 2024, ~3:00 PM - 3:20 PM UTC
Saturday, Dec 7 2024, ~4:00 PM - 4:20 PM CET (Europe/Paris)
Saturday, Dec 7 2024, ~5:00 PM - 5:20 PM EET (Europe/Athens)
Saturday, Dec 7 2024, ~8:30 PM - 8:50 PM IST (Asia/Kolkata)
Saturday, Dec 7 2024, ~11:00 PM - 11:20 PM +08 (Asia/Singapore)
Sunday, Dec 8 2024, ~12:00 AM - 12:20 AM JST (Asia/Tokyo)
Find out how to watch and participate

Description

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. (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".

  • 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

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

Questions or comments? Please e-mail ramin.honary@gmail.com

Back to the talks Previous by time: Managing writing project metadata with org-mode Next by time: The Future of Org Track: Development - Watch