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

Add comments completion

Open immae opened this issue 6 months ago • 1 comments

There used to be a bug in ledger mode which allowed comments (including tags & meta) to get completed because they were somehow wrongly parsed as an account. This bug was very useful to me since I rely a lot on tags in my accounting, and its fixing made my work much harder.

This change is an attempt to re-add the completion feature (disclaimer: the code was bootstrapped with an LLM but failed to produce any usable result; however it helped me understand how lisp works and find relevant functions, so most of the code is still written by me)

As is, the code does the job, but it contains a few issues (it’s still a win as is in my opinion):

  • The listing doesn’t get cached (not sure it is a problem, the completion is very fast for me)
  • The listing is incomplete: it only lists account comments, not comments that appear on the same line after payees or prices (but completion still works in these positions)
  • The completion itself could be improved: it completes immediately with a whole string instead of completing until biggest common
  • The implementation of the search-forward should probably rely on ledger-comment-string but the regexp seems incorrect as is

/cc @simonmichael

immae avatar Sep 03 '25 07:09 immae

I've gone ahead and added a test for comment completion, and also taken the liberty of making some tweaks to the completion behavior. Since I don't use this, it may be helpful if you could please test it out and see how the new behavior feels to you. (Notably, I changed the boundaries so that the entire comment region including the comment marker is being completed).

bcc32 avatar Dec 07 '25 08:12 bcc32

@bcc32 I just added your changes don’t see any difference with what I had before, so I guess it’s a good sign? I think I understand what you changed and it seems fine by me anyway!

Thanks for your improvement and the tests!

immae avatar Dec 19 '25 12:12 immae

Thank you for your contribution!

bcc32 avatar Dec 19 '25 23:12 bcc32