See previous articles for Part I and Part II.
It’s 2025. It’s not 1960 anymore.
What programming language should one use to re-implement emacs? Don’t use just one language, use every language.
Experiment: Purpose
Can we create an emacs clone that renders in a browser and is controlled programmatically from the command line in another terminal window?
Start with a small experiment. If this doesn’t produce usable results, there is no point in further experimentation. If it does produce usable results, keep pushing it further to see where it becomes too slow to be useful.
Test whether sending commands via websockets to a local browser is a viable way to edit text.
If the tests are promising, this would mean that we can build “plugins” using any programming language that runs on the command line.
The intention is to build an editor Part that can be controlled by source code written in the PBP DPL (Diagrammatic Programming Language). Plugins could be written as PBP parts.
If text editing, done this way, works reasonably, then we could build other types of editors, like diagram editors, etc., and plug them into our editor and our programming workflow.
Meta: This is essentially a client-server architecture for text editing. The currently popular technique of using Functional Programming does not encourage this kind of model. Servers are not functions. Essentially, one has to refrain from thinking that everything is a function and think in terms of strongly-isolated, free-running Parts. This kind of part-based thinking encourages the idea that parts can have multiple inputs and multiple outputs over time, that feedback is different from recursion, that state can be used when it is fully isolated and invisible to other parts in the system, that control flow also needs to be fully isolated in addition to encapsulation of data.
First experiment
Programmatically set cursor and “mark”. Programmatically select text between “mark” and current cursor position. Programmatically clear the selection.
Allow user to edit text and hit the SAVE button.
Open edit windows, allow user to make small edits then to hit SAVE button to send the changes back to the controller.
Create a window server in a browser, that takes commands, via a websocket, from the command line and sends error messages / update notices to another console via another websocket.
This experiment requires 3 console windows and 1 browser window.
We start up the server and response listener in consoles A and B.
We send commands on the command line from console C.
The first command creates new edit windows and specifies their id (string names).
Following commands container edit requests, specifying edit window ids.
We observed changes in the browser.
We send a command to close the server and response listener.
Example Session:
Terminal 1: Start server (console window A)
node websocket-server.js
Terminal 2: Start response listener (console window B)
node response-client.js
Terminal 3: Send commands (console window C)
Create windows
node send-client.js '[{"port":"","payload":{"request":"create new window","id":"ed-1","content":"Hello\nWorld"}},{"port":"","payload":{"request":"create new window","id":"ed-2","content":"Second window"}}]'
open browser tabs (2) as specified in console window A
Control editor
node send-client.js '{"port":"","payload":{"request":"set mark","id":"ed-1"}}'
node send-client.js '{"port":"","payload":{"request":"move cursor to position","id":"ed-1","position":5}}'
node send-client.js '{"port":"","payload":{"request":"highlight text","id":"ed-1"}}'
Close everything
node send-client.js ‘{"port":"","payload":{"request":"close"}}'
Observations, Code Repository
This works “fast enough” on a Mac Mini M2.
The experimental code can be found in the github repository emacsPBP.
Conclusions
It seems reasonable to continue with further experiments.
The next experiment might be to implement shortcut keys for actions like
Set mark.
Highlight a section of text between mark and cursor.
Delete highlighted section.
Save.
I think that this implies the need to send some responses back to the main controller in console window ‘C’.
MacOS, UNIX (Linux) runs orders of magnitude faster in 2025 than it did in the 1900s. It seems reasonable to use the console command line as a REPL for programming. It seems reasonable to use PBP diagrammatic source code for programming.
Further experimentation is indicated.
See Also
Email: ptcomputingsimplicity@gmail.com
References: https://guitarvydas.github.io/2024/01/06/References.html
Blog: guitarvydas.github.io
Videos: https://www.youtube.com/@programmingsimplicity2980
Discord: https://discord.gg/65YZUh6Jpq
Leanpub: [WIP] https://leanpub.com/u/paul-tarvydas
Twitter: @paul_tarvydas
Substack: paultarvydas.substack.com