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

Transaction folding

Open drdv opened this issue 5 years ago • 4 comments

Even though ledger-occur can be used to narrow down a buffer based on a regex, I find it useful to have, in addiction, folding of transaction records. This PR implements the latter. For example, folding a transaction

2011/01/02 Grocery Store
    Expenses:Food:Groceries                  $ 65.00
    * Assets:Checking

results in

2011/01/02 Grocery Store...

Two interactive functions are exposed:

  • ledger-mode-transaction-toggle-folding: hide/show transaction under point
  • ledger-mode-folding-toggle-transactions: hide/show all transactions in the buffer

ledger-occur and transaction folding can be used to complement each other.

The buffer-local variable ledger-mode-toggle-invisible-transactions can be used to enable/disable folding of invisible transactions (i.e., transactions whose overlay has been set using ledger-occur).

Transaction blocks are detected using the same approach as in ledger-highlight-xact-under-point (probably some code refactoring should be done).

The transaction folding functionality has been added to the ledger-occur.el file even though probably a new file should be used (my aim was to do the least amount modifications). The same thing applies to the unit tests.

The function ledger-occur-make-invisible-overlay has been modified by adding (overlay-put ovl 'display "") in order to avoid undesired trailing ellipsis when using ledger-occur together with transaction folding.

Overlay of type 'code has been used in order for incremental search to temporarily open folded blocks.

drdv avatar Jun 22 '20 20:06 drdv

Currently, the user might choose not to activate hs-minor-mode if he/she doesn't want to use the folding functionality. On the other hand, a warning is displayed when attempting to use the folding functionality without enabling hs-minor-mode.

drdv avatar Jun 22 '20 21:06 drdv

I'm just stumbling across this now, and I like this idea. Is there a reason why this PR was not merged? Currently, I'm using the simpler folding technique described here:

; M-1 to collapse all transactions to one line, M-0 to reset. Useful for quickly scanning
(global-set-key "\M-0" (lambda () (interactive) (set-selective-display (* tab-width 0))))
(global-set-key "\M-1" (lambda () (interactive) (set-selective-display (* tab-width 1))))
(add-hook 'ledger-mode-hook (lambda () (setq tab-width 4)))

josephmturner avatar Feb 08 '22 09:02 josephmturner

I don't know why it is not merged.

drdv avatar Feb 08 '22 09:02 drdv

@drdv can you squash this into one commit? cc: @bcc32

jdek avatar Mar 19 '24 20:03 jdek