vim-ledger icon indicating copy to clipboard operation
vim-ledger copied to clipboard

Long comments should wrap to new lines

Open igbanam opened this issue 1 year ago • 7 comments

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.

igbanam avatar May 20 '24 22:05 igbanam

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.

alerque avatar May 21 '24 08:05 alerque

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

  • t autowrap text using textwidth
  • c autowrap comments using textwidth
  • q enable formatting with gq
  • j remove the comment character when joining lines

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

igbanam avatar May 22 '24 08:05 igbanam

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?

alerque avatar May 22 '24 08:05 alerque

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?

  • Enter a simple transaction, like the "example" below
    • I have the payee long enough to mark textwidth
  • Indent the transaction line so a comment goes to textwidth
    • …just so we can notice the hang point clealy
  • Type some one or two characters afterwards`
  • Notice Vim hangs
  • Use <C-c> to unhang it

Example

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

igbanam avatar May 22 '24 08:05 igbanam

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 avatar May 22 '24 08:05 igbanam

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 avatar May 22 '24 08:05 igbanam

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

igbanam avatar May 22 '24 08:05 igbanam