New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
structured/"rich" text, text annotations/overlay #1767
Comments
#719 (comment) mentions scintillua, which looks like a very good alternative to regex for describing syntax. It doesn't solve your more general request, which I interpret as "text properties". Text properties are very important but will require careful design, and won't be possible until we achieve more fundamental changes such as abstracting the buffer structure. Currently in the n/vim core, a buffer is basically a character array (memline.c); trying to bolt-on text properties will result in terrible performance. |
vis's basic data structure (a piece chain) seems good for this kind of thing, but moving to that could require a major rewrite of the regexp engine. |
I saw vis appear on HN too, and it intrigues me a lot. Though at some points in the description I thought: we can't omit that (feature) as he has done, (n)vim needs it. Being able to mmap files into the memory pace is really really cool, but already breaks down when input conversion needs to be done, as said by @martanne (plus the fact that vim currently scans over the entire file to determine the encoding, which is cool since it has to read it into allocated memory anyway). |
@aktau If a buffer is opened with |
Yes, if the Most likely this is the majority case. But for example this would break down when opening binary files which are likely to fail the utf-8 test, which is usually when people really need large file support. I'm also not sure of the impact of such a split-up on the manageability of the code. As I understand it, the current mem{line,file} combo is actually quite clean. |
@aktau as soon as there's a NUL byte in the first few kBytes, the encoding should be seen as "binary", so the UTF8 test shouldn't matter here. |
Well, it's equally possible to keep that memory layout, and "just" have an additional map (array or hash or tree or whatever) that can deliver additional details for parts of a line... don't know whether that's the same kind of rewrite, though. |
As far as I can remember (got an unfinished blog post about this), if |
Like some sort of conversion overlay, you mean. This would work well for latin-X to utf-8 or the reverse, but more distincts encodings would probably suffer. |
All that said, I think perhaps an on-the-fly conversion overlay could work. It only being generated when a certain piece of the buffer is actually requested. I shudder at the thought of implementing this without any crazy bugs though. The thought-stuff sure is enticing. |
On the other hand, large files support seems like yet another concept that could be added on as a plugin. In the case of binary files, syntax/highlighting is obviously not needed, so a "view" of a file could be fed to In the case of a large log file, for which syntax/highlighting would be needed, nothing is lost because vim already has Some problems I can think of with this "view" approach:
Personally I really prefer trying to leverage robust external solutions and only enhancing the core by adding hooks. |
Another reason I like the plugin approach is that in the common case, loading the file in memory is not really a problem and avoids complication. When people load large files they are unhappy about one of two things:
If you load a giant C# (10 MB) file in Visual Studio, it will buckle (I know this for a fact). Add ReSharper and you might as well get some coffee. So you must either choose fast or good, and that means it is reasonable to disable some features (vim regex, whole-file analysis) on very large files. I am interested to hear other cases that I am missing which would break with the "partial view" approach. |
I wasn't actually thinking about 10MB files as large. It sounds like peanuts. I was more thinking of 1-50GB size files. Which would have trouble fitting in main memory. Off the top my head, I don't know how well (n)vim does with a 10MB source file (syntax highlighted and all), but I would consider it a failure if we don't solve that (in case it has issues). |
n/vim (with syntax highlighting and neocomplete) has no problem at all on the same 10 MB C# file (obviously VS/ReSharper are doing a lot more work on that file, so I don't mean to compare the two). I only raised that example to point out that one cannot expect all features in all scenarios. Migrating the buffer data structure of n/vim is pretty close to a total rewrite. I find it much more interesting to see how far we can get with alternative solutions. |
Hmm, to get back to my original request ... how about providing some kind of rich text buffer with some restrictions?
|
Is text properties not a correct interpretation of your original request? I don't understand what is new in the rich text buffer you describe. |
Yeah, text properties might be a good name for it, too. I'd need not only the highlighning class name, though - storing arbitrary data as well would be nice. |
Storing arbitrary data in association with a piece of text, and that association follows the text as edits are made. I believe the existing marks logic could be extended to do this, though it may not be scalable. |
As for an easy example, think about netrw directory listings with |
How about allowing arbitrary key/value pairs in the The advantage is that we reuse the existing mechanism for decorating text |
@phmarek If you can compute the position of the text to highlight since it is static, shouldn't it be possible to use Perhaps introducing a virtual key to tag separators (let's say
you could have
@tarruda That would be quite helpful, and not only for UIs. |
@fmoralesc That might be an option, too, but not much cleaner IMO. And, in the long run, I'd like to shoot for having a "text" property named |
|
@phmarek Sure, I was only thinking of the issue of having to specify different separators depending on the contents of the region, which that would solve. I think @tarruda's suggestion could help for implementing
to be displayed as a image, it's just that all UIs currently assume a grid of text. Expanding the
I've thought a mechanism like this could allow plugins like NerdTree to be displayed as native lists (like this), and special buffers to be displayed using non-fixed with fonts. @bfredl 👍 |
Not sure highlight is the right mechanism, rather |
@justinmk Probably. Extending both would be helpful. (As to extending Extending vimscript can also benefit vanilla vim, if the code could be proposed to |
Sure if vim_dev accepts, but otherwise extending vimscript really complicates the burden of compatibility (or managing, documenting, and providing solutions for incompatibility) and always requires difficult, time-hungry decisions. Incompatibility is always an option (and sometimes we will choose it), but we can also work on making our API really nice to work with (from vimscript, too, using |
The vimscript changes are minimal, all I'm proposing is to allow arbitrary key/value pairs after the For example, if a TUI and a GUI are connected to the same instance and need to display a highlight group, the TUI would check for ctermfg/ctermbg while the GUI would check for guifg/guibg and even richer information such as alpha level or images as suggested by @fmoralesc suggested. For associating the highlight information with arbitrary positions, I vote for @bfredl suggestion: a buffer-aware Besides being backwards compatible and allowing arbitrary formatting to be associated with text, this has the advantage of simplifying code (I estimate about 40% of syntax.c could be removed). |
@bfredl how is your tree-sitter work coming along? I had to open some multi-megabyte HTML files (terms and conditions) and had to switch highlighting off to move the cursor. That is how I stumbled here! |
@felipesere It will be one of my priorities after 0.4 is released (very soon, hopefully). |
I'm not sure if this is off-topic but #1767 (comment) got me thinking: Will it be possible, once the tree-sitter branch is merged, to use language-specific syntax objects like |
Yes. Directly from Lua, which is accessible from Vimscript. Initially however, we will provide only a query API. We will document patterns for using the API to query syntax, which can be used to create mappings. Later, we will think about adding first-class Normal-mode commands for common cases like "around Function" ( |
A lot of work has been done in this area. more focused issues / drafts are tracking pieces that are missing. |
With the new plugin structure and things like the MessagePack API, it becomes much easier to have external plugins; one thing that is still awkward is the coloring of information.
I'm thinking about a plugin here (slimv, to be exact, although many others would have the same issue) that wants to have its own buffer to display arbitrary information. To get some highlightning (of "active" fields and other parts), there have to be syntax rules that operate via string matching - and that is
concealcursor
,conceallevel
)How about being able to specify "classes" for (parts of) text, so that the syntax coloring rules can be applied directly without needing the RE engine inbetween? I imagine sending not a plain string for a line, but something like
["a string ", { class: "Error", text: "some error string"}, "more plain text"]
.If that could be stored in Neovim directly it should make lots of things easier - especially for the plugins if they could store (some) arbitrary information in the dictionary as well! (Currently such things have to be put into the line, concealed in some way, and then matched and parsed out again, which is awful.)
To give a specific example - currently a line looks like this:
while the visual display is
(and includes colors, of course).
The text was updated successfully, but these errors were encountered: