Added quick balance check to ledger-mode
This commit is contained in:
parent
98f8df5583
commit
33c046d068
3 changed files with 51 additions and 30 deletions
|
|
@ -233,6 +233,14 @@ automatically place any amounts such that their last digit is aligned to
|
||||||
the column specified by @code{ledger-post-amount-alignment-column},
|
the column specified by @code{ledger-post-amount-alignment-column},
|
||||||
which defaults to 52. @xref{Ledger Post Customization Group}.
|
which defaults to 52. @xref{Ledger Post Customization Group}.
|
||||||
|
|
||||||
|
@node Quick Balance Display
|
||||||
|
@subsection Quick Balance Display
|
||||||
|
You will often want to quickly check the balance of an account. The
|
||||||
|
easiest way it to position point on the account you are interested in,
|
||||||
|
and type @code{C-C C-P}. The minibuffer will ask you to verify the name
|
||||||
|
of the account you want, if it is already correct hit return, then the
|
||||||
|
balance of the account will be displayed in the minibuffer.
|
||||||
|
|
||||||
@node Editing Amounts, Marking Transactions, Adding Transactions, The Ledger Buffer
|
@node Editing Amounts, Marking Transactions, Adding Transactions, The Ledger Buffer
|
||||||
@section Editing Amounts
|
@section Editing Amounts
|
||||||
GNU Calc is a very powerful Reverse Polish Notation calculator built
|
GNU Calc is a very powerful Reverse Polish Notation calculator built
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,21 @@
|
||||||
": "))))
|
": "))))
|
||||||
(read-string default-prompt nil 'ledger-minibuffer-history default)))
|
(read-string default-prompt nil 'ledger-minibuffer-history default)))
|
||||||
|
|
||||||
|
(defun ledger-display-balance-at-point ()
|
||||||
|
"Display the cleared-or-pending balance.
|
||||||
|
And calculate the target-delta of the account being reconciled."
|
||||||
|
(interactive)
|
||||||
|
|
||||||
|
(let* ((account (ledger-read-account-with-prompt "Account balance to show"))
|
||||||
|
(pending (ledger-reconcile-get-cleared-or-pending-balance (current-buffer) account)))
|
||||||
|
(when pending
|
||||||
|
(if ledger-target
|
||||||
|
(message "Pending balance: %s, Difference from target: %s"
|
||||||
|
(ledger-commodity-to-string pending)
|
||||||
|
(ledger-commodity-to-string (-commodity ledger-target pending)))
|
||||||
|
(message "Pending balance: %s"
|
||||||
|
(ledger-commodity-to-string pending))))))
|
||||||
|
|
||||||
(defun ledger-magic-tab (&optional interactively)
|
(defun ledger-magic-tab (&optional interactively)
|
||||||
"Decide what to with with <TAB> .
|
"Decide what to with with <TAB> .
|
||||||
Can be pcomplete, or align-posting"
|
Can be pcomplete, or align-posting"
|
||||||
|
|
@ -120,6 +135,7 @@ Can be pcomplete, or align-posting"
|
||||||
(define-key map [(control ?c) (control ?t)] 'ledger-insert-effective-date)
|
(define-key map [(control ?c) (control ?t)] 'ledger-insert-effective-date)
|
||||||
(define-key map [(control ?c) (control ?u)] 'ledger-schedule-upcoming)
|
(define-key map [(control ?c) (control ?u)] 'ledger-schedule-upcoming)
|
||||||
(define-key map [(control ?c) (control ?y)] 'ledger-set-year)
|
(define-key map [(control ?c) (control ?y)] 'ledger-set-year)
|
||||||
|
(define-key map [(control ?c) (control ?p)] 'ledger-display-balance-at-point)
|
||||||
(define-key map [tab] 'ledger-magic-tab)
|
(define-key map [tab] 'ledger-magic-tab)
|
||||||
(define-key map [(control ?i)] 'ledger-magic-tab)
|
(define-key map [(control ?i)] 'ledger-magic-tab)
|
||||||
(define-key map [(control ?c) tab] 'ledger-fully-complete-xact)
|
(define-key map [(control ?c) tab] 'ledger-fully-complete-xact)
|
||||||
|
|
@ -163,6 +179,7 @@ Can be pcomplete, or align-posting"
|
||||||
(define-key map [toggle-xact] '(menu-item "Toggle Current Transaction" ledger-toggle-current-transaction))
|
(define-key map [toggle-xact] '(menu-item "Toggle Current Transaction" ledger-toggle-current-transaction))
|
||||||
(define-key map [sep4] '(menu-item "--"))
|
(define-key map [sep4] '(menu-item "--"))
|
||||||
(define-key map [recon-account] '(menu-item "Reconcile Account" ledger-reconcile))
|
(define-key map [recon-account] '(menu-item "Reconcile Account" ledger-reconcile))
|
||||||
|
(define-key map [check-balance] '(menu-item "Check Balance" ledger-display-balance-at-point))
|
||||||
(define-key map [sep6] '(menu-item "--"))
|
(define-key map [sep6] '(menu-item "--"))
|
||||||
(define-key map [edit-amount] '(menu-item "Calc on Amount" ledger-post-edit-amount))
|
(define-key map [edit-amount] '(menu-item "Calc on Amount" ledger-post-edit-amount))
|
||||||
(define-key map [sep] '(menu-item "--"))
|
(define-key map [sep] '(menu-item "--"))
|
||||||
|
|
|
||||||
|
|
@ -73,29 +73,28 @@ reconcile-finish will mark all pending posting cleared."
|
||||||
:group 'ledger-reconcile)
|
:group 'ledger-reconcile)
|
||||||
|
|
||||||
|
|
||||||
(defun ledger-reconcile-get-cleared-or-pending-balance ()
|
(defun ledger-reconcile-get-cleared-or-pending-balance (buffer account)
|
||||||
"Calculate the cleared or pending balance of the account."
|
"Calculate the cleared or pending balance of the account."
|
||||||
(interactive)
|
|
||||||
;; these vars are buffer local, need to hold them for use in the
|
;; these vars are buffer local, need to hold them for use in the
|
||||||
;; temp buffer below
|
;; temp buffer below
|
||||||
(let ((buffer ledger-buf)
|
|
||||||
(account ledger-acct))
|
(with-temp-buffer
|
||||||
(with-temp-buffer
|
;; note that in the line below, the --format option is
|
||||||
;; note that in the line below, the --format option is
|
;; separated from the actual format string. emacs does not
|
||||||
;; separated from the actual format string. emacs does not
|
;; split arguments like the shell does, so you need to
|
||||||
;; split arguments like the shell does, so you need to
|
;; specify the individual fields in the command line.
|
||||||
;; specify the individual fields in the command line.
|
(if (ledger-exec-ledger buffer (current-buffer)
|
||||||
(if (ledger-exec-ledger buffer (current-buffer)
|
"balance" "--limit" "cleared or pending" "--empty" "--collapse"
|
||||||
"balance" "--limit" "cleared or pending" "--empty" "--collapse"
|
"--format" "%(display_total)" account)
|
||||||
"--format" "%(display_total)" account)
|
(ledger-split-commodity-string
|
||||||
(ledger-split-commodity-string
|
(buffer-substring-no-properties (point-min) (point-max))))))
|
||||||
(buffer-substring-no-properties (point-min) (point-max)))))))
|
|
||||||
|
|
||||||
(defun ledger-display-balance ()
|
(defun ledger-display-balance ()
|
||||||
"Display the cleared-or-pending balance.
|
"Display the cleared-or-pending balance.
|
||||||
And calculate the target-delta of the account being reconciled."
|
And calculate the target-delta of the account being reconciled."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((pending (ledger-reconcile-get-cleared-or-pending-balance)))
|
(let* ((pending (ledger-reconcile-get-cleared-or-pending-balance ledger-buf ledger-acct)))
|
||||||
(when pending
|
(when pending
|
||||||
(if ledger-target
|
(if ledger-target
|
||||||
(message "Pending balance: %s, Difference from target: %s"
|
(message "Pending balance: %s, Difference from target: %s"
|
||||||
|
|
@ -104,9 +103,6 @@ And calculate the target-delta of the account being reconciled."
|
||||||
(message "Pending balance: %s"
|
(message "Pending balance: %s"
|
||||||
(ledger-commodity-to-string pending))))))
|
(ledger-commodity-to-string pending))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun is-stdin (file)
|
(defun is-stdin (file)
|
||||||
"True if ledger FILE is standard input."
|
"True if ledger FILE is standard input."
|
||||||
(or
|
(or
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue