Skip to content

Can't break on textwidth #838

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

Closed
snoblenet opened this issue Dec 10, 2024 · 5 comments
Closed

Can't break on textwidth #838

snoblenet opened this issue Dec 10, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@snoblenet
Copy link
Contributor

snoblenet commented Dec 10, 2024

Describe the bug

By default, I can't break long lines using jqG.

I tried changing and deleting the formatexpr. When I do, I can break long lines using jqG, but the result is not indented correctly.

Sample document, before formatting:

* How to Stop an Outdoor Table from Feeling Sticky After Oiling
** Pro Tips
    - *Choose the Right Oil:* Use a quick-drying outdoor oil, such as teak oil or tung oil, designed for exterior furniture.
    - *Clean the Table:* Ensure the table is free from dirt, dust, or old finish before applying the oil.
    - *Temperature and Humidity:* Apply oil when temperatures are moderate (around 50–80°F) and humidity is low for optimal drying.

try this:

-- no change to orgmode's formatexpr
vim.cmd('setlocal textwidth=80')
vim.cmd('setlocal formatoptions=acjnqlt')
gqG

result:

no change

try this:

set formatexpr=nvim_treesitter#formatexpr()
vim.cmd('setlocal textwidth=80')
vim.cmd('setlocal formatoptions=acjnqlt')
gqG

result:

* How to Stop an Outdoor Table from Feeling Sticky After Oiling
** Pro Tips
   - *Choose the Right Oil:* Use a quick-drying outdoor oil, such as teak oil or
     tung oil, designed for exterior furniture.
     - *Clean the Table:* Ensure the table is free from dirt, dust, or old
       finish before applying the oil.
     - *Temperature and Humidity:* Apply oil when temperatures are moderate
       (around 50–80°F) and humidity is low for optimal drying.

try this:

set formatexpr=
vim.cmd('setlocal textwidth=80')
vim.cmd('setlocal formatoptions=acjnqlt')
gqG

result:

* How to Stop an Outdoor Table from Feeling Sticky After Oiling
** Pro Tips
   - *Choose the Right Oil:* Use a quick-drying outdoor oil, such as teak oil or
     tung oil, designed for exterior furniture.
     - *Clean the Table:* Ensure the table is free from dirt, dust, or old
       finish before applying the oil.
     - *Temperature and Humidity:* Apply oil when temperatures are moderate
       (around 50–80°F) and humidity is low for optimal drying.

desired result:

* How to Stop an Outdoor Table from Feeling Sticky After Oiling
** Pro Tips
   - *Choose the Right Oil:* Use a quick-drying outdoor oil, such as teak oil or
     tung oil, designed for exterior furniture.
   - *Clean the Table:* Ensure the table is free from dirt, dust, or old finish
     before applying the oil.
   - *Temperature and Humidity:* Apply oil when temperatures are moderate
     (around 50–80°F) and humidity is low for optimal drying.

Steps to reproduce

n/a

Expected behavior

n/a

Emacs functionality

n/a

Minimal init.lua

n/a

Screenshots and recordings

No response

OS / Distro

15.1.1

Neovim version/commit

0.10.2

Additional context

n/a

@snoblenet snoblenet added the bug Something isn't working label Dec 10, 2024
@kristijanhusak
Copy link
Member

There is a bug with a fallback, so I'll look into that, but from where are you getting nvim_treesitter#formatexpr() ? nvim-treesitter is not exposing that function.

@kristijanhusak
Copy link
Member

I pushed a fix that should properly fallback to the internal formatting for the lines that are not affected by the org formatting. Let me know if this fixes it for you.

@snoblenet
Copy link
Contributor Author

Thanks.

gqG still does not work.

However, if I do gqap on one paragraph at a time, it works, though I'd expect an extra space before each line following a bullet.

I get this:

* How to Stop an Outdoor Table from Feeling Sticky After Oiling
** Pro Tips
    - *Choose the Right Oil:* Use a quick-drying outdoor oil, such as teak oil
     or tung oil, designed for exterior furniture.
    - *Clean the Table:* Ensure the table is free from dirt, dust, or old finish before applying the oil.
    - *Temperature and Humidity:* Apply oil when temperatures are moderate
     (around 50–80°F) and humidity is low for optimal drying.

I'd expect one more space before or tung oil and before (around 50.

@kristijanhusak
Copy link
Member

Does it work when you do not use any formatexpr, or the one you provided from treesitter (even though I'm still not sure where it's coming from) ? In your example only headlines are being really formatted by orgmode, rest is being handled by internal formatting.

https://neovim.io/doc/user/options.html#'formatexpr'

When the expression evaluates to non-zero Vim will fall back to using
the internal format mechanism.

@snoblenet
Copy link
Contributor Author

snoblenet commented Dec 11, 2024

Yes. The three scenarios above were:

  1. no change to orgmode's formatexpr
  2. set formatexpr=nvim_treesitter#formatexpr()
  3. set formatexpr=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants