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

virt_lines support #35

Closed
5 tasks done
jbyuki opened this issue Aug 10, 2022 · 19 comments
Closed
5 tasks done

virt_lines support #35

jbyuki opened this issue Aug 10, 2022 · 19 comments

Comments

@jbyuki
Copy link
Owner

jbyuki commented Aug 10, 2022

virt_lines poc

image

requires nvim 0.8.0+

A safe way to get inline visualization. The implementation is currently very simplistic.
Enable with:

require"nabla".enable_virt()

Disable with:

require"nabla".disable_virt()

Note: enable_virt only supports the inline syntax which is $ .. $. Currently $$ .. $$ will likely throw an error.
Works as expected with the new treesitter support.

Options:

require"nabla".enable_virt({
  autogen = true, -- auto-regenerate ASCII art when exiting insert mode
  silent = true,     -- silents error messages
})

TODO:

  • : colorization
  • : disable/enable virt_lines when switching mode insert/normal
  • : support inline conceal as well, so that the preview is not shifted upwards.
  • : virt_lines above and below for the best centering.
  • : multi line
@kkharji
Copy link

kkharji commented Aug 11, 2022

Nice @jbyuki well done. I wonder if it would be possible to hide $..$ in like normal mode so the buffer will be more readable.

@jbyuki
Copy link
Owner Author

jbyuki commented Aug 13, 2022

Conceal is added.

@kkharji
Copy link

kkharji commented Aug 13, 2022

Great @jbyuki will try it out in few days. Thanks.

@kkharji
Copy link

kkharji commented Aug 13, 2022

I had to chance to interact with math equation. Does the conceal only hides $? if so, sorry I mean't hiding everything between $.

Also it seems I need to call require"nabla".enable_virt() each time I introduce new changes. Maybe on switch to normal mode it could be called automatically?

@jbyuki
Copy link
Owner Author

jbyuki commented Aug 13, 2022

I'm not the brightest, yes it makes more sense. Only hiding the $ will not make any difference...

New commits completely hides the equation. But still some work need to be for alignment.

Yes, we could add an autocommand which disable & enable nabla everytime the user enters normal mode.

@kkharji
Copy link

kkharji commented Aug 13, 2022

🤣Not true, happens to the best of us.

image

So this is a quick test of a previous file I shared with current state.

https://gist.github.com/kkharji/39bf5e931534e45a3b7b6ed2ec478273

It seems to ignore spaces between latex element, mathbb key, unable to handle multiple $..$ at the same line and causing crazy amount of space, I'm guessing because the virtual position is relative and only account for $..$ block

@jbyuki
Copy link
Owner Author

jbyuki commented Aug 15, 2022

Yeah, the code was just full of bugs.
The alignement should now be correct. I'm not collapsing the formulas into a single character because otherwise we get issues with long warping lines and alignement of formulas.

@Slotos
Copy link

Slotos commented Aug 17, 2022

Would it be possible to add toggle_virt() or virt_enabled status flag?
The latter would allow for conditional mappings akin to "show popup or refresh virtual text".

@jbyuki
Copy link
Owner Author

jbyuki commented Aug 17, 2022

It's added. toggle_virt() and is_virt_enabled().

@andreasusc
Copy link

Im getting

E5108: Error executing lua /Users/skreli/.config/nvim/plugged/nabla.nvim/lua/nabla.lua:140: atte
mpt to index local 'g' (a nil value)

@jbyuki
Copy link
Owner Author

jbyuki commented Sep 7, 2022

@andreasusc

This is not normal. This indicates that the ascii generation failed but it should output an error instead.
Could you tell what input/buffer content you used?

@samuzora
Copy link

samuzora commented Sep 8, 2022

Hi, I'm getting the error above as well, seems like single-line expressions are causing the issue.

$$1$$
...
E5108: Error executing lua ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:140: attempt to index local 'g' (a nil value)
stack traceback:
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:140: in function 'colorize_virt'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:474: in function 'enable_virt'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:571: in function 'toggle_virt'
        [string ":lua"]:1: in main chunk

The above content will trigger the error on calling :lua require("nabla").toggle_virt(). On changing to inline expressions the error does not occur.

A similar error is triggered on popup():

$$1$$
...
E5108: Error executing lua ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:51: attempt to index local 'g' (a nil value)
stack traceback:
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:51: in function 'colorize'
        ...are/nvim/site/pack/packer/start/nabla.nvim/lua/nabla.lua:380: in function 'popup'
        [string ":lua"]:1: in main chunk

however still displays the popup with nil as content

image

Hope this helps 😃

@jbyuki
Copy link
Owner Author

jbyuki commented Sep 8, 2022

Actually for enable_virt(), it only supports the inline syntax which is $ .. $. I should be more clear about that.

EDIT: I will push a fix for that shortly.

jbyuki added a commit that referenced this issue Sep 8, 2022
@krishnakumarg1984
Copy link

https://gist.github.com/kkharji/39bf5e931534e45a3b7b6ed2ec478273

Hey. Thanks for this nice implementation. There were some typos in the file in the gist. I have fixed them and uploaded an edited version here: https://gist.github.com/krishnakumarg1984/9d311585d96d5f834f200d4163749bc8

@max397574
Copy link
Contributor

would it be possible to ignore $$$$ or [ ] instead of erroring?
so if you have a document which has both $$ and the other ones you could use virt_lines for the things which are supported yet?

@adoyle-h
Copy link

adoyle-h commented Oct 24, 2022

How to remove spaces to align left?

@jbyuki
Copy link
Owner Author

jbyuki commented Oct 25, 2022

@adoyle-h I have changed the defaults to align left.
It's still possible to align in the center with enable_virt({align_center=true}).

@adoyle-h
Copy link

@jbyuki LGTM. Thank you. 👍

@ghostfish0
Copy link

ghostfish0 commented Sep 14, 2023

Good day :)

Whenever I use toggle_virt() to enable virt_lines the document automatically reset to nowrap. Is this the intended behavior? If not, are there any configs to turn it off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants