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

ledger-navigate-beginning-of-xact does not recognize commented transactions

Open presto8 opened this issue 3 years ago • 1 comments

Currently, ledger-navigate-beginning-of-xact does not recognize commented transactions. However, the font styling rules will highlight a commented transaction. This leads to unexpected behavior; for example, invoking C-c C-d (ledger-delete-current-transaction) while the cursor is on a commented transaction will not delete the (commented) transaction that the cursor is on, but rather it will search up in the buffer to the first non-commented transaction and delete that one.

This is the regex used to find the beginning of a transaction:

"^[=~[:digit:]]"

I'm not sure if this is the best solution, but expanding it to allow one or more comment characters followed by any amount of whitespace might work?

"^\\(;+\\s-*\\)?[=~[:digit:]]"

presto8 avatar Oct 01 '21 17:10 presto8

I think a sensible fix for this would be to have C-c C-d (ledger-delete-current-transaction) throw an error if it doesn't detect that it's on a valid transaction.


Current behavior:

C-c C-d (ledger-delete-current-transaction) will delete the transaction under point, but if there isn't a transaction at point, it will continue searching backwards until it finds one, and then deletes it (ledger-navigate-beginning-of-xact is at fault for this)

The problem with this is you can destroy a transaction that's completely out of the context of where point is at. Not very intuitive for the user! If you're looking at a list of tag or account directives, this comment will shoot you as far back as it needs to delete a transaction!


Proposed behavior:

Have C-c C-d (ledger-delete-current-transaction) only delete the transaction at point if it's valid. Add some validation to prevent any unintuitive behavior.

jstamant avatar Sep 25 '23 21:09 jstamant