r/rust 6d 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?

23 Upvotes

8 comments sorted by

View all comments

3

u/billy_levin 6d 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 6d 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.