Transaction folding
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 pointledger-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.
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.
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)))
I don't know why it is not merged.
@drdv can you squash this into one commit? cc: @bcc32