9 ms·
Build Your Own Text Editor
- dpc_pw 7y agoShameless plug. I'm working on a somewhat novel modal text editor: https://github.com/dpc/breeze https://github.com/dpc/breeze 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.
- akkartik 7y agoInteresting. I had this experience with Kakoune: https://lobste.rs/s/v17gol/switching_sublime_text_from_vim_2017#c_7dbqc1 https://lobste.rs/s/v17gol/switching_sublime_text_from_vim_2.... I'm curious if you expect to improve on it along the dimensions I mentioned.
- dpc_pw 7y agoHa! I have a very similar experience and I agree with all your points. I really enjoy the basic experience and `kak` is my main text editor ATM, but some details and parts of the philosophy are infuriating me. I started `breeze` as a prototype way to show kakoune author how kak could potentially work https://github.com/mawww/kakoune/issues/2590 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.
- adrusi 7y agoThe lack of built-in window management is a major feature of kakoune for me. I try to delegate all window management to my window manager, including such things as browser tabs, so I like that kakoune is designed to be used like that. The biggest downside of kakoune's approach for me is that it makes vimdiff-functionality pretty hard to achieve.
- spectaclepiece 7y agoOk(Event::Mouse(_)) => { // no animal support yet } ;)
- mushishi 7y agoI didn't notice actual design ideas (apart from the philosophy which sounded good to me). Do you have things on your mind on what kind of actions user can do? 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.
- asdjlkadsjklads 7y agoCool! I wanted to do similar things, neat idea. These days i'm wanting to try something similar but with a nice UI - i'm so tired of the Terminal, but it's hard to get away because editors like Kakoune and Vim are just so powerful. 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.
- cschmidt 7y agoThere is a ticket about this that might interest you. It seems like there is work to do, but that it might get there https://github.com/xi-editor/xi-editor/issues/1187 https://github.com/xi-editor/xi-editor/issues/1187
- tambourine_man 7y agoOne of NeoVim’s goals was to also be a backend to multiple front ends. The eternal dream of having Vim on a <textarea> or when writing email. I don’t know how far they’ve come as I switched back to Vim when version 8 came out.
- dpc_pw 7y agoI doubt this will ever happen. It's all about complexity, and in case of text editors there are layers and layers of abstractions that often (for UX reasons) have to be integrated tightly. Trying to unpack all pieces into fully generic bring-your-own implementation is going to be a lot of work upfront and in maintenance, and complexity explosion. 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.
- jhallenworld 7y agoThanks, I had not known about Kakoune (or breeze). It's interesting looking at Kakoune's issue list. The idea for the editor is good, but you can see the huge of amount of work needed to make a feature complete bug free editor. Also it's interesting to see the code when you write with the latest iteration of C++ instead of ancient versions of C.
- frogfish 7y agoWhat I instantly liked is, how literally it starts from scratch and builds a couple of lines at a time. Can anybody refer to a similar step by step guide to building a compiler?
- markus_zhang 7y agoGame scripting mastery, pretty much line by line, and you have the source code for each chapter.
- pkaye 7y agoThere is an old one on compilers called "Let's build a compiler by Jack Crenshaw" Its in Pascal but I think there are modern rewrites of it (like C on an x86)
- pjmlp 7y agoHere it is, https://compilers.iecc.com/crenshaw/ https://compilers.iecc.com/crenshaw/ As for modern, one can follow along using Free Pascal.
- TehShrike 7y agoIt's not finished yet, but you probably want https://craftinginterpreters.com/ https://craftinginterpreters.com/ I loved his "Game Programming Patterns" book, and this new book is looking totes spiffy
- minieggs 7y agoI enjoyed Kyle James' "The Super Tiny Compiler." https://github.com/jamiebuilds/the-super-tiny-compiler https://github.com/jamiebuilds/the-super-tiny-compiler
- mhh__ 7y agohttp://www.penguin.cz/~radek/book/lets_build_a_compiler.pdf http://www.penguin.cz/~radek/book/lets_build_a_compiler.pdf PDF form of "let's build a compiler" as mentioned by others (Haven't read it fully myself but I hear it's a very good introduction) 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-to-write-your-own-language/240165488 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.
- Ididntdothis 7y agoA long time ago I had to write a Windows custom control for text rendering. This was really hard to do in a performant way once you dealt with different fonts, pages sizes, scrolling and all the other stuff we usually take for granted. One of the most painful months in my life but I learned a lot since nobody told me how to do this so I had to make it all up.
- kevas 7y agoI’d love if you go into more detail.. dealing with similar ish right now and would love to hear other war stories
- deleted 7y ago[deleted]
- ankuranand 7y agoshameless Plug: I'm working on writing this in Go(Golang). https://github.com/ankur-anand/goditor https://github.com/ankur-anand/goditor
- japanoise 7y agoEven more shameless: I used it as a base for my own ersatz-emacs in golang! https://github.com/japanoise/gomacs https://github.com/japanoise/gomacs This is actually my go-to editor for small files/quick edits now
- dualogy 7y agoGood stuff for reminding me that `x/sys/unix` exists and the terminal-raw-mode it allows. Should inspire someone out there eventually to plumb everything in pure Go that people would otherwise seek from ncurses, GNU readline lib etc.
- _ph_ 7y agoYou should attach a license to your code.
- bArray 7y agoShameless plug - Text editor in 512 bytes (1kb if you include the kernel): https://bitbucket.org/danielbarry/saxoperatingsystem/src/master/PROGRAMS/EDIT/EDIT.ASM https://bitbucket.org/danielbarry/saxoperatingsystem/src/mas...
- emmanueloga_ 7y agoIn the same vein there's kilo by antirez: https://github.com/antirez/kilo 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!).
- userbinator 7y agoTo contrast with most of the "write your own small text editor" articles out there, I feel compelled to post this: http://kparc.com/$/edit.k http://kparc.com/$/edit.k 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...
- max_ 7y agoWow! a text editor in 3 lines of code? It would be nice if a short write up accompanied this?
- aidos 7y agoObligatory clip: Game of Life in APL https://youtu.be/a9xAKttWgP4 https://youtu.be/a9xAKttWgP4
- geocar 7y agoMaybe this will help? I wrote the following up a few years ago now: https://news.ycombinator.com/item?id=8476633 https://news.ycombinator.com/item?id=8476633
- drudru11 7y agoThanks for that write up. Is there a decent reference or tutorial for ‘k’ online that you would recommend? I would like to learn more about it’s semantics. For example, the views concept and how old versions of a view/var? Are available.
- geocar 7y agoNot to my knowledge. There are a fair number of documents[1] describing the language to be sure, but it is difficult to divorce K from its implementation(s), so k2, k3, k4, k5 (etc) are all different languages. Your best bet is to download some implementations and try it out. k4 is built-in to kx's q which has a free download[3], just enter a line with a backslash on it to get into k. 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/technical/documents/kusrlite.pdf http://web.archive.org/web/20041022042401/http://www.kx.com/... [2]: https://web.archive.org/web/20130801233812/http://www.kuro5hin.org/story/2002/11/14/22741/791 https://web.archive.org/web/20130801233812/http://www.kuro5h... [3]: https://kx.com/ https://kx.com/
- proverbialbunny 7y agoIn case anyone hasn't seen it this CppCon talk https://youtu.be/sPhpelUfu8Q https://youtu.be/sPhpelUfu8Q talks about rrb-trees and how they're a great data structure for writing a text editor that can handle unlimited sized documents without locking up, and allows for editing while saving and opening, and an easy way to support an undo command. 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.
- lioeters 7y agoFor those like me who are unfamiliar with Relaxed Radix Balanced trees, here's the paper presenting the algorithm: RRB-Trees: Efficient Immutable Vectors (2012) https://infoscience.epfl.ch/record/169879/files/RMTrees.pdf 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 https://hypirion.com/thesis.pdf Article: https://hypirion.com/musings/thesis https://hypirion.com/musings/thesis Code: https://github.com/hyPiRion/c-rrb https://github.com/hyPiRion/c-rrb
- mekanicalsyncop 7y agoAre there any good ones that exist? I'm a security analyst and I frequently work with large text files, 200MB-1GB and the text editors I've tried are incredibly slow. 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.
- proverbialbunny 7y agoThe person from the talk may have a github repo with the text editor he wrote shown in the talk.
- cjohansson 7y agoI’d recommend xi-editor, vi/vim/neovim or emacs for that
- dang 7y agoThread from 2017: https://news.ycombinator.com/item?id=14046446 https://news.ycombinator.com/item?id=14046446
- jokoon 7y agoMy big fear about implementing a text editor is writing a rope data structure to be able to edit large files. I don't really know if it's mandatory for all text editors though. 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.
- abainbridge 7y agoIn my text editor, I just use a doubly linked list of lines, instead of a rope. It doesn't limit the performance in any situation I've found. A performance problem I do have is large column mode edits. eg if I want to delete the first columns of the entire file (typically some log file with timestamps at the start). I suspect the rope data structure would make that worse. I like the simplicity of the doubly linked list of lines. I'm not sure what advantage the rope data structure would bring.
- wruza 7y agoI think that ring buffers as lines could do a little speedup in that specific case and shift/unshift ops.
- PeterisP 7y agoDoubly linked list of lines tends to be slow on, for example, editing documents with very long "lines" e.g. doing a find/replace on a 10mb json that's not pretty-printed and is a single line.
- fsloth 7y agoIf you use c++ you can start with a std::vector. Computers are really fast. Don’t optimize prematurely. And hey, maybe you don’t need a rope. Just put std::vectors to a std::map or std::list per row of text? Lots of problems that have an optimal complex solution can be solved with way simpler constructs in the prototyping phaze.
- abainbridge 7y ago
- nesadi 7y agoThis looks like fun. Does anybody know of other guides for different kinds of programs (other than compilers, which I've seen tons of here on HN)?
- a_e_k 7y agoHow about ray tracing? Peter Shirley (whom I learned a ton from in grad school) wrote a trilogy of mini-books beginning with "Ray Tracing in One Weekend." https://github.com/RayTracing/raytracinginoneweekend https://github.com/RayTracing/raytracinginoneweekend
- baby 7y agoThis is a pretty awesome resource! I wish this existed for Rust.
- bluecheese33 7y agoI followed this guide but implemented it in rust. https://github.com/khadiwala/kilo-rs https://github.com/khadiwala/kilo-rs If you’d like to take a look.
- dancek 7y agoI had the same plan. Thanks for the link, nice to have a reference if I get stuck (as a Rust noob).
- samatman 7y agoI very much enjoyed this article, as a sort of kata. 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.
- pawelduda 7y agoDisclaimer: I haven't read the article just yet. Saving it for later. 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.
- AsyncAwait 7y agoThis is about programming your own text editor, not configuring one to your requirements.
- pawelduda 7y agoWhich is what writing vim script essentially is. Or if vimscript is not enough, you can use literally any other language and integrate it via vimscript. I'm not an expert though but I have spent quite a lot of time on doing that.
- AsyncAwait 7y agoI get that ViM is really powerful, so is Emacs and the like, however I'd guess a large part of going into the trouble of building your own text editor would be to learn about the algorithms and data structures used, something you can't do by writing ViM configuration files.
- pawelduda 7y agoGood point - if someone is after that, then what I wrote isn't the best way to achieve this
- sweeneyrod 7y agoNo it isn't.
- pawelduda 7y agoI'd be more willing to change my mind if you provided something else than that.
- be5invis 7y agoI don't see any references to things like HarfBuzz or DWRITE, which are NECESSARY to properly display any scripts that's not European. All properly implemented text editors are rich text — because you will need to support font fallback and BiDi and all the Unicode complexity
- kbsletten 7y agoDid you see that this is a command line app (like VI, or EMACS)? Those libraries look like they're used for GUIs. Do you know if they can be used for the terminal?
- coldtea 7y agoYou absolutely don't need any of these for a tutorial text editor... Those are all things you can hook-in later, after you've understood how to make text editors...
- teddyh 7y agoI prefer The Craft of Text Editing by Craig A. Finseth: https://www.finseth.com/craft/ https://www.finseth.com/craft/
- tzs 7y agoQuote (from memory) from Rob Pike, a few years before he wrote the editor "sam": "Everybody writes a screen editor. It's easy to do and makes them feel important. Tell them to work on something useful". 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.
- markus_zhang 7y agoThanks for sharing. Just wondering how did ones write an editor in one night.
- retpirato 7y agoif you use windows (or linux with wine) you can write self-contained apps using Autohotkey. It's free from autohotkey.com. It's usually advertised as a macro-recorder which it also does.
- jason_slack 7y agoAs the author/maintainer of a once popular text editor I feel it is easy to get started then very hard to finish. Modern text editors require a lot of details and even more demands from those who use it. It’s a fun programming challenge. I still find myself thinking about awesome features to add.
- freyariki 7y agoProviding flexible Custom App Development Services. Know more: https://www.2basetechnologies.com/services/custom-business-application-development https://www.2basetechnologies.com/services/custom-business-a...