Closed jessegrosjean closed 3 years ago
@jessegrosjean Thanks for bringing this up!
My general goal for these sorts of things documentation-wise is to give them each an example file in the repo (in the examples
directory). For instance, I recently added a search-and-replace example, since it's not necessarily obvious how to most efficiently implement that kind of functionality on top of Ropey.
I think this is an excellent candidate for an example in the repo. I'll keep this issue open until I (or someone else) gets around to adding it.
In the mean time, Smith uses Ropey as its backing text storage, and it has syntax highlighting. I haven't looked at their highlighting code, so I'm not sure if it meets what you're looking for, but it's probably worth a look.
EDIT: Having said all of that, this is also a problem space with a lot of potential solutions with different trade-offs, so any example will likely be on the basic side. A more sophisticate approach would be something like in Rope Science 11 from Xi Editor, where instead of tracking all spans at a fine-grained level, you instead track parser state at a coarse level (every N lines or so) and use that to calculate things on-the-fly when needed.
Note to self: this would probably fit best as an addition to the simple_buffer
example.
I still haven't gotten around to this after two years. And I think part of the reason is that it's a bit overwhelming to try to provide documentation/examples for this in a way that's generally useful. There are a variety of approaches to syntax highlighting, cursor management, etc. which are all things that touch on this. But I think ultimately those topics are just out-of-scope for Ropey's documentation.
Moreover, there are now quite a few text editors out there that use Ropey, and which include syntax highlighting, etc. So even if someone wants Ropey-specific examples (which I don't think is necessary anyway--the solutions aren't specific to Ropey) people can look to those code bases for examples.
I'm wondering if you have any suggestion for efficiently tracking marked ranges? Issue #13 touched on this but was closed before you had a chance to comment.
I agree with issue #13, it can (probably should) be done in external structure. But an efficient implementation is non-trivial. I'm thinking something like https://github.com/atom/superstring marker_index as a good example of what is needed. It would be great to have this structure as an option to go with ropey. Or at least in the documentation to have some suggestions (maybe another crate) on how to handle the use case of tracking ranges in a ropey buffer.