ledger / vim-ledger

Vim plugin for Ledger
GNU General Public License v2.0
366 stars 56 forks source link

Long comments should wrap to new lines #158

Open igbanam opened 2 months ago

igbanam commented 2 months ago

When typing a comment, it wraps to the same line instead of wrapping to a new line.

https://github.com/ledger/vim-ledger/assets/390059/2faa926c-08f2-4b52-bf28-b921d050e600

I haven't done any extra customizations to the plugin. I am on the bleeding edge of Vim 9.

alerque commented 2 months ago

That's somewhat surprising! And I've never seen anything like it..

I'm on NeoVIM 0.10 over here, but definitely don't have the same problem:

image

I'm pretty skeptical that only this plugin alone is causing such a problem, this seems like some weird plugin interaction bug.

igbanam commented 2 months ago

Yup! Beats me too. The closest I've come to debugging this is… for some reason, formatoptions=tcqj is not being respected.

:h fo-table says this is meant to

Doesn't look like Neovim is autowrapping comments either — peep the that indents there. Looks to me like the line ran out of screen space

alerque commented 2 months ago

My formatoptions is set to tcqlr12Bj by default, but I just tried your settings (again my end is NeoVIM) and didn't see a problem.

Are you sure you don't have this issue with other file types?

igbanam commented 2 months ago

Holy sheet! I found it 😭😭😭

https://github.com/ledger/vim-ledger/blob/7b97c8765bf920e92fd950a7a5bc37cb2b13a494/ftplugin/ledger.vim#L23

ledger#align_formatexpr is effectively ledger#align_commodity which may not be applicable to comments. Commenting out this line — the one that sets is as formatexpr — fixes the issue. We don't want to incessantly format while we type. :LedgerAlign and :LedgerAlignBuffer can do the job after the typing is done.

On comment lines, it causes the behaviour in the OP. On transaction lines it actually hangs Vim. — I'm curious to see what it does in Neovim.

How to test?

Example

2023-01-01 * lskdjfl skdjf lsdkjflskdjf lskdjf lsdkjf lskdjf lskdjf lksdjf lksdj
  Expenses                                         92837923 USD ; lsdkfsdlfksj-X-kjl
;                                                                              ^
;                                                                              |
;                                                                             here
igbanam commented 2 months ago

I just tested this out in Neovim and it doesn't seem to be a problem. The lines don't wrap, but it doesn't hang either

igbanam commented 2 months ago

Hold that thought…

In Neovim, g:ledger_max_width=0 (i.e. textwidth=0) — this may be the reason we don't see the problem in Neovim

igbanam commented 2 months ago

NVM it's the same in Vim as well. I don't know why it breaks in Vim and not in Neovim

But commenting out the formatexpr line works for me