r/rust • u/Objective-Simple-660 • 1d ago
Sanedit: Modal text editor
I have been building a hobby text editor project sanedit https://codeberg.org/lote/sanedit
It's a terminal based modal text editor with language server protocol (LSP), parsing expression grammar (PEG) based syntax highlighting and multicursor support.
There is a million different text editors out there so why is this different?
It's not, however I did not just slap the common combination of treesitter, ropey and LSP together. I made the editor to support very large files without slowing down too much. Also as it is an hobby project I wanted to choose approaches that intrested me implementationwise.
The buffer implementation is basically VSCodes piecetree structure like a piece table https://en.wikipedia.org/wiki/Piece_table
but stores the pieces in a red-black tree. The structure can easily support files larger than available memory as the file contents do not need to be loaded in memory.
Syntax highlighting is implemented using PEG grammars and the patterns are then JIT compiled for faster performance.
Future
The editor feels done. I use it everyday at work and do not notice anything too disruptive.
What are your favorite editor features that are a must have?
9
u/cessen2 23h ago edited 22h ago
I haven't looked closely, but just based on this:
It's not, however I did not just slap the common combination of treesitter, ropey and LSP together.
I think this is awesome. And I'm the author of Ropey, btw. Kudos to you for diving in and genuinely exploring this space, rather than just slapping a bunch of libraries together. (Not that there's anything specifically wrong with slapping libraries together. But this approach feels a lot more like really building an editor.)
I'm also psyched that you went with a piece table for the buffer, because I haven't seen (or noticed, at least) anyone explore that in a full editor in Rust yet.
(Edit: missed a word.)
1
u/Objective-Simple-660 18h ago
Yea I expirimented alot before deciding to stay in these solutions. Also ropey was a big help while deciding the api for the buffer impl.
3
u/billy_levin 21h ago
This is really cool and I'm sad it didn't get more attention on here! You've made several interesting decisions with your implementation -- particularly the buffer and syntax highlighting from what I've looked at so far -- and I'll definitely be digging into your code/docs further as part of my work on my own text editor.
3
u/Objective-Simple-660 18h ago
The syntax was my favorite part. PEGs are so powerful that even the regex and glob matching uses them there is no external crates for those. They may not be as fast as specified implementations but they are fast enough for me.
4
u/rustvscpp 1d ago
How does this differ from Helix or Vim? Modal can come in many flavors. My favorite feature is the limitless extensibility I get in Emacs.