Hacker News new | past | comments | ask | show | jobs | submit

Writing my own text editor, and daily-driving it

https://blog.jsbarretto.com/post/text-editor
loading story #47336361
loading story #47338398
I went the same path of writing a text editor from scratch. There are a lot of moving parts, so I tried to outsource as much features as possible - LSP for intellisense, tree-sitter for highlighting and syntax-aware features, fzf for search and file handling, etc. I also tried to design it so that it can be tweaked to one's needs with simple code changes, suckless-style.

It was indeed a pain using it for the first few weeks, where every 5 minutes I found some bug and had to go back and fix it, instead of steadily working on some other project. Good news is more bugs you fix, less bugs is left.

https://github.com/ivanjermakov/hat

loading story #47335879
loading story #47335083
Fond memory of when I wrote an editor in the 90's because we didn't want to use "ms edit" for COBOL and asm files.

Syntax coloring, fast buffering and even a screen saver.

You could even call the compiler directly from it.

All this running on a pentium 120 and it felt a thousands times faster than today's vscode.

But vscode can edit multiple files at the same time...

loading story #47333795
I love this! The line “resist the urge to push the difficult bits off to a box of statistics” particularly resonated with me!
loading story #47338016
Josh Barretto is the genius behind the Super Mario 64 GBA port. I would gladly use his editor.
I use my own text editor too. Nobody else seems to get value from it. I’m still surprised by the value we get from home grown solutions.
loading story #47331862
loading story #47331678
This feels like two steps up from a highly customized vim config. But I want one step up.

I want to be able to piece together an editor from modular task specific executables. Different programs for file searching, input mapping, buffer modification and display, etc. Probably similar to how LSPs are already separated from most editors.

One step less hardcore than writing a whole editor.

Anyone know of any existing projects along these lines?

Acme [1]

It steps back from the “customize everything” mantra, believing that approach leaves users with an underdeveloped essential system. But it still has two major APIs: one for window manipulation [2], the other for text-based integration with the surrounding system via plumber [3].

All textual CLI tools (that is, those without pseudographics) work by default and are the heart of its style.

I use Acme for everything except web browsing (although most links are still managed by Acme).

[1]: http://youtu.be/dP1xVpMPn8M

[2]: http://9p.io/magic/man2html/4/acme

[3]: http://9p.io/sys/doc/plumb.html

loading story #47334409
loading story #47333348
loading story #47333589
loading story #47333115
loading story #47337793
Should make my own text editor. Would make for an interesting project at least.
I would recommend using the ropey crate for easy performance gains. A string buffer is quick to implement but you will hit a wall as soon as you need to edit large files.
loading story #47333752
loading story #47334386
loading story #47337722
loading story #47333443
loading story #47332645
loading story #47338481
loading story #47335813
loading story #47333005
loading story #47332682
Building your own editor seems to be one of those projects that teaches you far more about software design than using any existing one.

Did anything in your approach change how you think about everyday tooling?

Author here. Off the top of my head:

- Software is simpler than you think when you boil it down. There's a massive incentive to over-sell the complexity of the problem a solution is trying to solve, to pull in users. This is true both for proprietary products and, to a lesser degree, FOSS. You can probably replace most of the tools you use day-to-day in a weekend or two - provided you keep practising the art of just building stuff. I'm not saying that you should, but it's worth keeping in the back of your head if a tool is driving you mad.

- You can achieve 80% of the functionality with 20% of the work required to build an off-the-shelf solution. In a surprising number of cases, you can do the same with 20% of the integration cost of an off-the-shelf solution. A lot of software is - to put it quite bluntly - shit (I include a lot of my own libraries in this list!). There are probably only a few hundred really valuable reusable software components out there.

- Aggressively chase simplicity and avoid modularity if you want to actually achieve anything. The absolute best way to never get anything useful out of a project is to start off by splitting it into a dozen components/crates/repositories. You will waste 75% of your time babysitting the interfaces between the components rather than making the thing work.

- Delete code, often. If you look at the repo activity (https://git.jsbarretto.com/zesterer/zte/activity/code-freque...) you'll see that I'm deleting code almost as much as I'm adding it, especially now that I've got the core nailed down. This is not wasted effort: your first whack at solving a problem is usually filled with blunders so favour throwaway code that's small enough to keep in your head when the time comes to bin it and make it better.

- It is absolutely critical that you understand the fundamental mode of operation of the code you've already written if you want to maintain development velocity. As Peter Naur said, programming is theory-building and the most important aspect of a program is the ineffable model of it you hold in your head. Every other effort must be in deference to maintaining the mental model.

loading story #47334354
loading story #47332234