Skip to content
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

feat!: rewrite TOhtml in lua #27097

Merged
merged 1 commit into from Feb 28, 2024
Merged

feat!: rewrite TOhtml in lua #27097

merged 1 commit into from Feb 28, 2024

Conversation

altermo
Copy link
Contributor

@altermo altermo commented Jan 20, 2024

The reasoning behind the rewrite

  1. Some neovim-specific decorations (mainly extmarks and treesitter) don't get handled by TOhtml.vim.
  2. TOhtml.vim is written in Vim script, and to not make it slow, they needed to write some hard-to-understand code, and lua is so much faster, that there is not much need to use magic to write fast code.
  3. TOhtml.vim is not updated that often (typically once every few years) so there's no need to worry about rewriting every new feature of TOhtml.vim in lua.

What this rewrite is not
As @clason described, this rewrite needs not to be a full rewrite of TOhtml.vim (with all the features), so it is not.

What this rewrite is
This rewrite has the purpose of creating a plugin which can convert a vim window with all it's decorations to html.

The visual things that still don't work

  • LSP semantic tokens that are not on the screen
  • Highlighted folds
  • More complex internal statuscol (number+relativenumer+{foldcolumn or signcolumn})
  • Right aligned extmarks
  • Extmarks' hl_mode
  • Spell
  • Priority for specific decorations
  • Less used highlight attributes (font, special color, reverse, underdouble, blend, ...)

Related:

@clason
Copy link
Member

clason commented Jan 20, 2024

Question to the Neovim maintainer: Do we need to support everything that TOhtml.vim does?

Ideally, yes. The assumption should be that the output is exactly what's seen on the screen. But it's ok not to support everything in a first MVP that can be merged, if the design is such that it can be added in followup PRs.

This also implies that we don't need to support every feature and option from the legacy :TOhtml (which users can still install as a plugin if they pine for the good old days). Focus on the primary use case (hardcopy/offline viewing), and only implement what is needed for that. (This is an opportunity for simplification and better maintainability, importantly.)

Specifically:

  1. linking URLs would be good but not needed for an MVP;
  2. no progress bar (Lua is hopefully fast enough that you don't need one);
  3. no interactivity/lots of settings (just set the right Vim options before :TOhtml, which gives you a preview for free);
  4. no legacy web engines, no legacy encodings (Neovim is utf-8 only).

@altermo

This comment was marked as resolved.

@altermo altermo force-pushed the tohtml-in-lua branch 3 times, most recently from 68dc4b3 to e5fa933 Compare January 20, 2024 10:26
runtime/plugin/tohtml.lua Outdated Show resolved Hide resolved
@clason
Copy link
Member

clason commented Jan 20, 2024

I think it's OK to keep the syntax file (and even preferable; makes syncing with Vim runtime slightly easier).

@altermo altermo force-pushed the tohtml-in-lua branch 2 times, most recently from 4aaa9fb to f016aae Compare January 20, 2024 11:26
runtime/plugin/tohtml.lua Outdated Show resolved Hide resolved
runtime/plugin/tohtml.lua Outdated Show resolved Hide resolved
@altermo altermo force-pushed the tohtml-in-lua branch 18 times, most recently from c23ae2d to fb9392a Compare January 21, 2024 13:48
Copy link
Member

@clason clason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! Thank you for tackling this!

runtime/doc/lua.txt Outdated Show resolved Hide resolved
@clason
Copy link
Member

clason commented Feb 27, 2024

(Also needs a rebase.)

@altermo altermo force-pushed the tohtml-in-lua branch 4 times, most recently from 37a4848 to f1671be Compare February 27, 2024 15:58
@altermo
Copy link
Contributor Author

altermo commented Feb 27, 2024

I accidentally messed up the commit, how to fix it? (did to fast, need to go somewhere, don't have time to fix)

@clason
Copy link
Member

clason commented Feb 27, 2024

Yeah, I'm afraid that you messed it up properly. Disentangling will take some time and effort. You need to git restore to "open up" the commit and carefully stage all your changes before committing again.

@clason
Copy link
Member

clason commented Feb 27, 2024

(As far as I can see, only gen_vimdoc.py returning from the dead is spurious, so you might get away with git rming that and squashing again. But you should carefully look at the diff to make sure nothing got lost.)

@altermo altermo force-pushed the tohtml-in-lua branch 3 times, most recently from 82dd3e2 to 58aa945 Compare February 27, 2024 17:55
@altermo altermo force-pushed the tohtml-in-lua branch 2 times, most recently from c6c4fe4 to e62afa3 Compare February 27, 2024 18:02
@altermo
Copy link
Contributor Author

altermo commented Feb 27, 2024

Okay, fixed the commit.

@altermo altermo force-pushed the tohtml-in-lua branch 2 times, most recently from b7a98e4 to 7d37f3b Compare February 27, 2024 18:15
runtime/lua/tohtml.lua Outdated Show resolved Hide resolved
Co-authored-by: wookayin <wookayin@gmail.com>
Co-authored-by: clason <c.clason@uni-graz.at>
Co-authored-by: Lewis Russell <me@lewisr.dev>
@lewis6991 lewis6991 merged commit 2f85bbe into neovim:master Feb 28, 2024
27 checks passed
@github-actions github-actions bot removed the request for review from gpanders February 28, 2024 16:26
@clason
Copy link
Member

clason commented Feb 28, 2024

I just noticed a minor issue: the newly opened buffer with the HTML inherits filetype=help instead of setting it to html.

@neovim neovim locked as resolved and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
runtime funtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants