SlideShare a Scribd company logo
Writing an Editor in Elixir
today we’re gonna edit like it’s 1999
Just how are you
planning to bore me?
Why do this? Why???
Ok, get on with it
then.
(I only have to sit here for 45 minutes)
My story?
(the details of my life are quite inconsequential)
Initial release in 1974
Computer user since
1979
(core gamer, dude)
1. BLOAD SUPERINV
2. <press play on tape>
3. <wait 10 minutes>
4. BRUN SUPERINV
(something like that — I was 5 in 1979)
5. PLAY SPACE INVADERS!
Coding since 1982


10 PRINT “IAN ”
20 GOTO 10
Editing since 1993
(when I met my first love, Emacs)
Future roadmap?
(destination unknown)
So why not write an
editor?
(‘cause we need more of those…)
What makes an editor
successful?
Why do some come and
go while others persist?
Why do neckbeards
cling to 1970s tech?
(or does it cling to them?)
Why do hipsters insist on
editing through 20 layers
of abstraction?
(css goes well with a latte, and I’ve got 16 cores man)
In the beginning…
ED
ED
(still the best on a teletype…)
vi
(also created in 1976…)
vim
update in 1991
Smalltalk
(go wild man)
The GUI Era
“You’re Welcome”
— Java
Intellij / Eclipse /
Netbeans
(‘cause I like editing through a peephole)
"Modern" Editors
(yeah, man… air quotes)
TextMate
(because I’m smart enough to know that
Notepad is inadequate)
Sublime
(for when you need a break from broken Emacs)
Atom
“I use Atom cause I like mediocre editors”
— ElixirConf2017 Trainer
Please, what’s wrong with my
Atom?
(the whole point for me is it should just work)
Some of this may
have offended you
(and that’s an important clue)
It’s because, as programmers,
we often have a deep, personal
relationship with our editor.
(we’ve spent more time with it than anyone else!)
It’s about power and
productivity.
(sometimes a delicate balance)
So again, why do
this?
I love Emacs, but things
have been rough lately..
Maybe it’s a syntax
thing
And, as a hacker, I want
to write my own.. :)
And we have this great
language that is
simultaneously a perfect
and a terrible choice for
this.
Great because…
High level
Easy to develop in
Great for orchestration
Durability through OTP
Code reloading
Terrible because…
Mainly because the GUI ecosystem is
pretty limited
That just hasn’t been Erlang’s or
Elixir’s strength
I have arrows in my back to prove
this!!!
But we can fix this!
Let’s invent on
principle.
(or rather, in this case, shamelessly steal!)
A nice correspondence
Emacs Emx
C core Rust core
Elisp Elixir
Dynamic typing Dynamic typing
Code reloading Code reloading
Eval Eval
DSLs DSLs
Mutable Immutability
Beachballs Concurrency
Foundational Features
Programmable

Composable

Introspectable
Basic Design
Rust for low-level
(where necessary)

Back-end

(Elixir)

Front-ends
(text, GUIs)
Core / Back-end
Sessions:
have multiple buffers
shared or not
Buffers:
text, files, etc
rust-backed for performance (maybe?)
Event-maps:
map input actions to state transformations
Front-ends and
Sessions
Sessions
Front-ends
Buffers
defprotocol for multiple implementations:

• Sting-based
• Elixir “ropes”
• Rust “ropes”
Buffers
Buffers
Buffers
Buffers
Event-maps
Can be code or data
Stateless
Allows for easy code-
reloading
Key-code parsing
Key-code parsing
Ropes
Ropes
Basically a string as a
binary tree
Balancable
Ropes
Index(i): character at i, (log N)
Concat(S1, S2): concatenate two ropes, O(1) (or O(log N))
Split (i, S): split into two ropes O(log N)
Insert(i, S’): insert string at i O(log N)
Delete(i, j): delete the substring Ci..Cj, O(log N)
Report(i, j): output the string Ci..Cj, O(j + log N)
Elixir Ropes
I updated a library
Thank you @copenhas on github.
I did a PR.
Can I publish it to hex.pm?
Rust Ropes
In development.
Makes use of Ropes from the Xi
project.
Will integrate as Rustler resource
object.
Front-end
terminal 

(tty_sl, others)
Wx

(:wx provided by OTP)
Electron
(just kidding, but why not, help me add it?)
Exui
(maybe? Boyd and I are already talking)
BEAM/OTP is 500k lines
of C code and 2.4 M lines
of Erlang code!
Atom / Electron is
scary?
Front-end protocol
Connect to backend, receive a session
Send input events (keys, mouse, etc.)
Receive output events, render
(sound familiar anyone?)
escript
mix.exs
mix.exs
escript
GenServer
escript
erl start options
—no-input
(don’t read input)
—no-shell
(don’t start the erl shell)
GenServer
escript
escript
IO.Ansi
IO.Ansi didn’t have cursor
movement stuff
Emx.Ansi
Maybe it should be core?
But there were some
issues
You can't have erlang shell or IEx
with it (terminal ownership conflict)

I couldn't get IEx —remsh working
wth it (even with elixir, mix, iex, etc
running)…
(someone please help?)
Maybe a port?
Do what IEx does?
IEx replaces the erlang shell
erl … -user Elixir.IEx.CLI
The erlang shell
There’s a great explanation of how it works here:
https://ferd.ca/repl-a-bit-more-and-less-than-that.html
I’ll summarize it quickly
“Old” shell
“New” shell
IO Protocol
Phoenix uses this during code
reload.
Basically send/receive bytes/
characters as messages.
Enables remote
shells
Replace tty_sl?
Let erlang think it’s in control
of the terminal.
We’ll secretly control the
terminal.
Run our back-end as
a port-driver?
It can own the terminal and
provide the shell.
This is really a variation of the
other ideas.
Use a pty?
We’ll can start erlang with a pty
so it thinks it owns the terminal.
This has the benefit of letting us
do other-language front-ends
that run a backend over the pty.
Remember this guy?
We can fake it with a pty
We can fake it with a pty
Rust-based PTY
Front-end
TODO: show termion code.
But why another node?
My old friend, telnet
The name stands for
"teletype network”
Basically “terminal over network”
This is a prototype, so start simply.
Eventually this should be SSH.
My old friend, telnet
Ranch Telnet
GenServer1
Ranch Telnet
Telnet.SessionHandler
Ranch Telnet
Telnet.SessionHandler
Let’s try connecting
telnet <my_ip_here> 5555
Wx
If you want to do cross-platform GUI work, your
options are really limited
They fall into a few basic categories:

Looks native on the platform (lowest common
denominator, WX)
Looks the same everywhere (consistency of
implementation over consistency of look)
:wx erlang module
:wx.observer
:wx.demo
:wx erlang module
:wx.wx_object
How to wrap the
constants
But this is tedious
So I wrote a library.
And then I found this post ! :)
WxWidgets
code wrapping
helpers for records and
constants
adapt for elixir idioms
Very basic, still needs
work
:wx wraps WxWindows directly… so…
All the arguments are in the wrong
order!
Makes fluid interfaces hard
Also needs docs
I think I will find some way to
wrap and import the docs from
WxWindows and attach them
to the right methods
Code wrapping
Code wrapping
Tell me if there’s a better way, but I
think macros might obscure too much…
use WxObject
And voila!
wx_const(:FOO)
WxObjectServer
Supervising
(YMMV, not sure how well this works yet…)
Let’s try it out.
TIL
(please learn from my mistakes)
Don’t spend days fighting
with regexs, use a parser.
(you are clearly using the wrong tool)
Combine is great, but
it still needs laziness.
Lazy Parsing in Combine
Do not name your
top-level module Wx
(you’ll spend hours wondering why things don’t
work — I still don’t know why)
Codez
https://github.com/ijcd/wx_widgets
https://github.com/ijcd/ropex
https://github.com/ijcd/emx
(available soon)

More Related Content

PDF
KEY
Rails development environment talk
PPTX
Thumbcoil: How we got here...
PPT
scaling compiled applications - highload 2013
PDF
Alias as usual
KEY
Hybrid concurrency patterns
PDF
Let's talk about elixir - 26th Athens Ruby Meetup
ODP
Rails development environment talk
Thumbcoil: How we got here...
scaling compiled applications - highload 2013
Alias as usual
Hybrid concurrency patterns
Let's talk about elixir - 26th Athens Ruby Meetup

What's hot (15)

PDF
Practical Puppet: Systems Building Systems
PDF
Ruby Programming Introduction
PDF
Culerity - Headless full stack testing for JavaScript
PPTX
ODP
PPTX
Kotlin L → ∞
PPTX
Ruby Loves Dot Net
PDF
Melnytskyi Artem "A Little About the Bugs in the Code"
PDF
Elixir for rubysts
PPTX
introduction to server-side scripting
KEY
Actors and Threads
PDF
Melnytskyi Artem "A Little About the Bugs in the Code"
PDF
Using Erlang on the RaspberryPi to interact with the physical world
PDF
Ruby Presentation
PPTX
Async and Parallel F#
Practical Puppet: Systems Building Systems
Ruby Programming Introduction
Culerity - Headless full stack testing for JavaScript
Kotlin L → ∞
Ruby Loves Dot Net
Melnytskyi Artem "A Little About the Bugs in the Code"
Elixir for rubysts
introduction to server-side scripting
Actors and Threads
Melnytskyi Artem "A Little About the Bugs in the Code"
Using Erlang on the RaspberryPi to interact with the physical world
Ruby Presentation
Async and Parallel F#
Ad

Similar to ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan (20)

PDF
Bugs from Outer Space | while42 SF #6
PDF
Killer Bugs From Outer Space
PDF
The Holistic Programmer
PDF
Os Keysholistic
PDF
Peyton jones-2011-parallel haskell-the_future
PDF
Simon Peyton Jones: Managing parallelism
PDF
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
PDF
What is Elm and Why Should I Care?
PDF
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
ODP
x86 & PE
ODP
Character sets and iconv
PPT
What does OOP stand for?
ODP
An introduction to erlang
PDF
Erlang, an overview
PDF
Lab4 scripts
PPTX
Computer Science Architecture Lesson.pptx
PDF
Infrastructure as code might be literally impossible part 2
PDF
Boo Manifesto
PDF
Unmanaged Parallelization via P/Invoke
PDF
Sheffield_R_ July meeting - Interacting with R - IDEs, Git and workflow
Bugs from Outer Space | while42 SF #6
Killer Bugs From Outer Space
The Holistic Programmer
Os Keysholistic
Peyton jones-2011-parallel haskell-the_future
Simon Peyton Jones: Managing parallelism
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
What is Elm and Why Should I Care?
Gabriele Santomaggio - Inside Elixir/Erlang - Codemotion Milan 2018
x86 & PE
Character sets and iconv
What does OOP stand for?
An introduction to erlang
Erlang, an overview
Lab4 scripts
Computer Science Architecture Lesson.pptx
Infrastructure as code might be literally impossible part 2
Boo Manifesto
Unmanaged Parallelization via P/Invoke
Sheffield_R_ July meeting - Interacting with R - IDEs, Git and workflow
Ad

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Nekopoi APK 2025 free lastest update
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
L1 - Introduction to python Backend.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Introduction to Artificial Intelligence
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Wondershare Filmora 15 Crack With Activation Key [2025
Nekopoi APK 2025 free lastest update
Adobe Illustrator 28.6 Crack My Vision of Vector Design
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms I-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Odoo Companies in India – Driving Business Transformation.pdf
top salesforce developer skills in 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan