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

Long comments should wrap to new lines #158

Open
igbanam opened this issue May 20, 2024 · 7 comments
Open

Long comments should wrap to new lines #158

igbanam opened this issue May 20, 2024 · 7 comments

Comments

@igbanam
Copy link

igbanam commented May 20, 2024

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

Screen.Recording.2024-05-20.at.23.30.02.mov

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

@alerque
Copy link
Member

alerque commented May 21, 2024

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
Copy link
Author

igbanam commented May 22, 2024

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

@alerque
Copy link
Member

alerque commented May 22, 2024

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
Copy link
Author

igbanam commented May 22, 2024

Holy sheet! I found it 😭😭😭

setl formatexpr=ledger#align_formatexpr(v:lnum,v:count)

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
Copy link
Author

igbanam commented May 22, 2024

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
Copy link
Author

igbanam commented May 22, 2024

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
Copy link
Author

igbanam commented May 22, 2024

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

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

2 participants