what's new in aretext 0.5?
Today marks the fifth release of aretext, the minimalist text editor with vim-compatible key bindings! This post describes the highlights.
(Wait, what’s that? You say you want to install it right now? Well, then just go straight to the installation docs!)
Faster fuzzy menu search
Aretext uses a trie-based fuzzy find algorithm for selecting files in a menu. This worked well for most projects… until I ran it after building Kubernetes. It turns out that the Kubernetes build process creates many paths with UUIDs. By definition, UUIDs are unlikely to share prefixes, so representing them in a trie could require millions of nodes. Fortunately, there was a straightforward solution: path compression. Combining trie nodes with unique prefixes greatly reduced the number of nodes in the trie, eliminating the performance issue for random strings!
Idle CPU usage
Sometimes, fixing one performance issue can cause another. A while back, I noticed that aretext was a bit slow when copy-pasting large amounts of text into the terminal emulator. Profiling showed that the bottleneck was redrawing the screen after each terminal event, so I changed the redraw loop to poll every 20ms and redraw if necessary. Unfortunately, polling caused aretext to use more CPU while idle (about 0.4% on my M1 Macbook air and 3-4% on a Surfacebook with WSL2). Commit 3098dc removes the polling, while still addressing the original performance issue. After the fix, idle CPU is almost always 0.0%.
(Mostly) accurate YAML syntax highlighting
I opened Issue #75: yaml syntax highlighting is inaccurate back in June. It turns out that YAML is an extremely complicated language. Aretext v0.3 introduced a new incremental parsing algorithm that could support context-sensitive languages like YAML, but every time I tried to implement the YAML spec I hit a wall. There were just too many edge cases.
Eventually, I realized that almost every syntax highlighter for YAML uses some heuristics that don’t exactly match the YAML spec. The new YAML parser in aretext is pretty gnarly, but it’s less than 400 lines and, as far as I can tell, about as accurate as other text editors. And look at those beautiful multi-line strings!
Protocol Buffer syntax highlighting
Aretext now provides syntax highlighting for protocol buffers! The language has a clear and simple spec, so unlike YAML it took only an afternoon to implement.
Cursor alignment on reload
If all changes to a document have been saved, and the file changes on disk, aretext reloads it automatically. But how does the editor know where to position the cursor? Prior versions of aretext used a silly heuristic: move the cursor to the same character offset from the beginning of the file (which may or may not be on the same line), then scroll until the cursor is visible. As a result, the cursor or scroll position would sometimes appear to “jump” on reload, which was very distracting.
To address this problem, aretext v0.5 introduces a diff-based alignment algorithm. It attempts to match lines between the old and new document using a simplified version of the patience diff algorithm. If an alignment is found, aretext will place the cursor at the equivalent line and column in the new document!
Case-insensitive text search
Prior versions of aretext supported only case-sensitive text search, which could make it difficult to find things. After much refactoring, aretext now supports case-insensitive text search as well! This works the same as vim’s “smartcase” option. Hopefully this makes it easier to find things in large documents!
Lots of exciting stuff planned:
- Line wrapping at word boundaries
- Built-in directory navigation (like NERDTree, but without installing any plugins)
- Syntax highlighting for markdown
- Starting to think about a roadmap to v1.0?