Build Your Own Text Editor
viewsourcecode.org
viewsourcecode.org
This was not long after he had left Caltech, where he had been a system admin/system programmer for CITHEP (Caltech High Energy Physics), for Bell Labs. CITHEP hired a few undergraduates as the new admins and system programmers. I was one of those undergraduates.
Most of us used the line-oriented editor QED, but as programmers were wont to do in the early '80s, said that someday we were going to write ourselves awesome screen editors.
One evening, Karl Heuer and I were both boasting about how great our screen editors would be, and it somehow turned into an editor writing throw down. We took terminals at opposite sides of the room, and both started hacking away, designing as we coded.
This continued all night, mostly in silence, with the occasional boast ("I've got text search working!") and counter-boast ("I had that an hour ago--I'm doing regular expressions now!"), and frequent trips downstairs to the vending machines for soda and snacks.
Another of the undergraduate system admin/programmers, Norman Wilson, then arrived, and saw what Karl and I had been doing all night. He sent an email to Pike about it, and the quote at the start was Pike's reply.
Just wondering how did ones write an editor in one night.
Most text editors today do not support such functionality. With lockless data structures like an rrb-tree it becomes easy. It really is an ideal way to do write a text editor.
RRB-Trees: Efficient Immutable Vectors (2012)
https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf
EDIT: For further reading:
Improving RRB-Tree Performance through Transience (2014)
https://hypirion.com/thesis.pdf
Article: https://hypirion.com/musings/thesis
A lot of the time I can use grep and other command-line tools to find what I need, but given the nature of the job I don't always know what I'm looking for so having the raw file open in a text editor is sometimes the only way.
This is a text editor written in K, an APL-family language. Determining how it works is left as an exercise to the reader. I wonder whether an explanation would be longer or shorter than the tutorial in the article...
It would be nice if a short write up accompanied this?
Views are just a convenient syntax for memoization. Old versions of the value aren't available.
[1]: http://web.archive.org/web/20041022042401/http://www.kx.com/...
[2]: https://web.archive.org/web/20130801233812/http://www.kuro5h...
[3]: https://kx.com/
http://johnearnest.github.io/ok/index.html
https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Manual....
https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Program...
↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵
A non obfuscated version is at http://kparc.com/edit.k where some stuff are explained.
sdj8340u2u$@(:@#P+_A:@L@#!@)_ZL?> M OW {E)@(
Can a language be invented where this random string I hammered out would be a valid program?
The k7/shakti tutorial playfully notes that running one's finger along the shifted top row of the keyboard is syntactically valid.
perl :-)
It's written in Rust, and it tries to improve on Kakoune, which tries to improve on Vi/Vim.
If you feel like hacking on a text editor, and would be interested - let me know.
I started `breeze` as a prototype way to show kakoune author how kak could potentially work https://github.com/mawww/kakoune/issues/2590 , and later decided that actually I could maybe push it further into a full new text editor.
I'd like to make it more natural to use, and get rid of the (IMO) pointless idiosyncrasies like the plugin API being keystroke based. I'd like to also make it easy to embed into other software, so that there's some hope that it could be easily integrated into existing software, so I'm not doomed to forever switch between kakoune and classic-vi editing.
The list of what already works seems just the same as in Vim.
I'm just curious what kind of modal system it actually is.
My wish is that you or I (if i ever have the time) will implement something like this onto XiEditor. Ie, implement this as a feature to a lower level editor backend, so that you get the frontends "for free".
It drives me nuts that there's so much work done for the frontend side of things, but the backend of editors are being reinvented repeatedly for little gain.
I hope Xi can make a performant, hackable backend to plug into solid frontends.
I don’t know how far they’ve come as I switched back to Vim when version 8 came out.
I really like some technical aspects of Xi, but I view it as a typical wishlist project/technical showcase. In the meantime projects like kakoune, with much smaller scale but better focus, in shorter time, build ecosystems that can be a practical Vim alternative.
Also it's interesting to see the code when you write with the latest iteration of C++ instead of ancient versions of C.
Can anybody refer to a similar step by step guide to building a compiler?
As for modern, one can follow along using Free Pascal.
I loved his "Game Programming Patterns" book, and this new book is looking totes spiffy
I haven't got a copy, but as far as I know Andrew Appel's book is structured in that manner, i.e. basic steps first then more advanced topics like garbage collection later.
"Engineering a compiler" is not step by step but very readable and contained if you want to skip the discussion of (say) various scanner implementations.
There is a decent sized gap between any real compiler and a related toy or book implementation (In general), so take a look at a compiler for a language you know (that isn't C++).
http://www.drdobbs.com/architecture-and-design/so-you-want-t... Walter Bright (of Digital Mars C++ and D fame) wrote an article about language implementation e.g. how to write a good compiler rather than a toy one.
I haven't found any better resource than nand2tetris, see Projects 6 to 12 where you start with an assembler and end up with a compiler [1]. There is the accompanying books [2] and coursera courses [3]. Hope this helps, best!
[1] https://www.nand2tetris.org/course
[2] https://www.nand2tetris.org/book
[3]https://www.coursera.org/courses?query=from%20nand%20to%20te...
[4]
But my point was that any of those editor parts aren’t really identifiable as it’s own thing outside of editing.
Would you be willing to pay for it (how much)? And what would be a good platform for this?
I'm doing this to pay bills while I work on something of my own. I will use C myself (might include a couple of 'parallel' videos for Rust too wherever applicable) but the way I explain, one would be able to use any programming language.
The contents would roughtly go like this-
1) Explaining the 'theory of computation', theoretical and not really necessary for learning how to build compilers but I love this topic and it does give you formal insight in the 'power' of computers and if you're going to build non-toy compilers, may help you write more efficient algorithms.
2) Tokenization and parsing.
3) Type system
4) Symbol table
5) Assembly
6) Brief introduction to some basic optimization techniques.
I want to hear if people here have ideas on how to go about doing this. Is there a good platform for interactive online coding+slides class?
I still haven't found a better introductory text than Appel's "Modern Compiler Implementation in ML". I also like pairing this with "Language Implementation Patterns", which uses ANTLR.
That said there are a couple of great books out there already, interpreterbook.com, compilerbook.com, and craftinginterpreters.com - all recommended. If you're doin g this for money you'll struggle, unless you have a lot of clarity / something new to offer.
I haven't had the stamina to go through one but have watched some sizable chunks and it's pretty cool, even with me not really knowing much about low-level stuff like that.
There's also a session where he live codes a vi-like text editor here: http://cowlark.com/2019-06-28-cpm-vi/index.html
https://inf.ethz.ch/personal/wirth/
Afterwards you can follow up with building an workstation OS on a systems programming language with GC, all the way from the boot sector loading code to the graphical UI, by reading and implementing "Project Oberon".
The 2013 edition uses an FPGA instead of the original Ceres hardware.
A̶n̶d̶ ̶s̶i̶n̶c̶e̶ ̶W̶i̶r̶t̶h̶ ̶d̶o̶e̶s̶ ̶n̶o̶t̶ ̶f̶e̶e̶l̶ ̶i̶t̶ ̶i̶s̶ ̶t̶i̶m̶e̶ ̶t̶o̶ ̶a̶c̶t̶u̶a̶l̶l̶y̶ ̶r̶e̶t̶i̶r̶e̶,̶ ̶h̶e̶ ̶h̶a̶s̶ ̶u̶p̶d̶a̶t̶e̶d̶ ̶t̶h̶e̶ ̶b̶a̶c̶k̶e̶n̶d̶ ̶t̶o̶ ̶t̶a̶r̶g̶e̶t̶ ̶R̶I̶S̶C̶ ̶V̶ ̶a̶s̶ ̶w̶e̶l̶l̶.̶
Are you confusing RISC-V with RISC5 [1]?
http://composition.al/blog/2017/07/31/my-first-fifteen-compi...
I haven't tried it yet, but it's on my list of "someday" projects
https://github.com/antirez/kilo
Edit: oops, yours is in assembly, so definitely not in the same vein :-p (except for both trying to be small!)
Edit2: ... and, the article is about kilo. D'oh. This is what happens when you go first through HN comments, only to later open the article (which I do often!).
I was a little frustrated with sublime text folding code using indentation instead of syntax (there's an issue but they don't want to fix it). I have large C++ files, and it seems visual studio does a better jobs at folding.
I like the simplicity of the doubly linked list of lines. I'm not sure what advantage the rope data structure would bring.
Lots of problems that have an optimal complex solution can be solved with way simpler constructs in the prototyping phaze.
I'd go further than that. I'd say in production too. If the simple thing is fast enough even when you test on a slow machine, then implementing the faster but more complicated data structure is a form of premature optimization.
On modern computers, you can get away with a flat buffer of text (not even a gap buffer) for documents up to a few megabytes. I don't really recommend a gap, because it adds complexity and doesn't help with the worst case, though of course it cuts your average case down.
If you're going for simpler than a rope, my recommendation is array of lines. You have to do logic to split and fuse lines (for example, when backspacing over a newline), but it's not too bad. The only thing they don't do really well is single long lines.
I don't recommend piece tables. They have superb performance on first load, but then fragment. The reason I'm such a huge fan of ropes is that they perform excellently in the worst case - long edit sessions, long lines.
Best of luck!
For scaling large docs, you can do a linked list of gap buffers and avoid re-allocs of large buffers.
Super simple, efficient enough for most “i wrote my own text editor”, can always plug in a more complex structure later.
Author’s implementation will drag down if you have very long lines (e.g., transpiled JS).
I started a clean repo, loaded stock vim, and typed every line in order.
Learned a lot! Kudos to the author and antirez, and may I suggest that it's worth working through slowly, as presented.
This is actually my go-to editor for small files/quick edits now
An alternative approach to this is to open vim with a blank .vimrc and add config as you need it. Nothing except what you REALLY need NOW to get things done. That's how I started my adventure with vim a few years ago and it's still paying off.
Do you really need `g?` (rot13) to get things done ?