Made account formatting and auto complete compatible.
This commit is contained in:
parent
27d27ecb6c
commit
b475e569c4
4 changed files with 72 additions and 63 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;; Load up the ledger mode
|
;; Load up the ledger mode
|
||||||
|
(require 'esh-util)
|
||||||
(require 'esh-arg)
|
(require 'esh-arg)
|
||||||
(require 'ldg-commodities)
|
(require 'ldg-commodities)
|
||||||
(require 'ldg-complete)
|
(require 'ldg-complete)
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,16 @@
|
||||||
"Options for controlling how Ledger-mode deals with postings and completion"
|
"Options for controlling how Ledger-mode deals with postings and completion"
|
||||||
:group 'ledger)
|
:group 'ledger)
|
||||||
|
|
||||||
(defcustom ledger-post-auto-adjust-amounts nil
|
(defcustom ledger-post-auto-adjust-postings nil
|
||||||
"If non-nil, ."
|
"If non-nil, adjust account and amount to columns set below"
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'ledger-post)
|
:group 'ledger-post)
|
||||||
|
|
||||||
|
(defcustom ledger-post-account-alignment-column 4
|
||||||
|
"The column Ledger-mode attempts to align accounts to."
|
||||||
|
:type 'integer
|
||||||
|
:group 'ledger-post)
|
||||||
|
|
||||||
(defcustom ledger-post-amount-alignment-column 52
|
(defcustom ledger-post-amount-alignment-column 52
|
||||||
"The column Ledger-mode attempts to align amounts to."
|
"The column Ledger-mode attempts to align amounts to."
|
||||||
:type 'integer
|
:type 'integer
|
||||||
|
|
@ -123,25 +128,25 @@ PROMPT is a string to prompt with. CHOICES is a list of
|
||||||
(- (or (match-end 4)
|
(- (or (match-end 4)
|
||||||
(match-end 3)) (point))))
|
(match-end 3)) (point))))
|
||||||
|
|
||||||
(defun ledger-align-amounts (&optional column)
|
(defun ledger-post-align-postings (&optional column)
|
||||||
"Align amounts and accounts in the current region.
|
"Align amounts and accounts in the current region.
|
||||||
This is done so that the last digit falls in COLUMN, which
|
This is done so that the last digit falls in COLUMN, which
|
||||||
defaults to 52. ledger-default-acct-transaction-indent positions
|
defaults to 52. ledger-post-account-column positions
|
||||||
the account"
|
the account"
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(if (or (null column) (= column 1))
|
(if (or (null column) (= column 1))
|
||||||
(setq column ledger-post-amount-alignment-column))
|
(setq column ledger-post-amount-alignment-column))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
;; Position the account
|
;; Position the account
|
||||||
(if (not
|
(if (not (and (looking-at "[ \t]+\n")
|
||||||
(and (looking-at "[ \t]+\n")
|
|
||||||
(looking-back "[ \n]" (- (point) 2))))
|
(looking-back "[ \n]" (- (point) 2))))
|
||||||
(progn
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(set-mark (point))
|
(set-mark (point))
|
||||||
(delete-horizontal-space)
|
(delete-horizontal-space)
|
||||||
(insert ledger-default-acct-transaction-indent))
|
(insert (make-string ledger-post-account-alignment-column ? )))
|
||||||
(set-mark (point)))
|
(set-mark (point)))
|
||||||
|
(set-mark (point))
|
||||||
(goto-char (1+ (line-end-position)))
|
(goto-char (1+ (line-end-position)))
|
||||||
(let* ((mark-first (< (mark) (point)))
|
(let* ((mark-first (< (mark) (point)))
|
||||||
(begin (if mark-first (mark) (point)))
|
(begin (if mark-first (mark) (point)))
|
||||||
|
|
@ -164,13 +169,13 @@ the account"
|
||||||
(insert " ")))
|
(insert " ")))
|
||||||
(forward-line))))))
|
(forward-line))))))
|
||||||
|
|
||||||
(defun ledger-post-align-amount ()
|
(defun ledger-post-align-posting ()
|
||||||
"Align the amounts in this posting."
|
"Align the amounts in this posting."
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(set-mark (line-beginning-position))
|
(set-mark (line-beginning-position))
|
||||||
(goto-char (1+ (line-end-position)))
|
(goto-char (1+ (line-end-position)))
|
||||||
(ledger-align-amounts)))
|
(ledger-post-align-postings)))
|
||||||
|
|
||||||
(defun ledger-post-maybe-align (beg end len)
|
(defun ledger-post-maybe-align (beg end len)
|
||||||
"Align amounts only if point is in a posting.
|
"Align amounts only if point is in a posting.
|
||||||
|
|
@ -180,7 +185,7 @@ BEG, END, and LEN control how far it can align."
|
||||||
(when (<= end (line-end-position))
|
(when (<= end (line-end-position))
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
(if (looking-at ledger-post-line-regexp)
|
(if (looking-at ledger-post-line-regexp)
|
||||||
(ledger-align-amounts)))))
|
(ledger-post-align-postings)))))
|
||||||
|
|
||||||
(defun ledger-post-edit-amount ()
|
(defun ledger-post-edit-amount ()
|
||||||
"Call 'calc-mode' and push the amount in the posting to the top of stack."
|
"Call 'calc-mode' and push the amount in the posting to the top of stack."
|
||||||
|
|
@ -221,8 +226,7 @@ BEG, END, and LEN control how far it can align."
|
||||||
|
|
||||||
(defun ledger-post-setup ()
|
(defun ledger-post-setup ()
|
||||||
"Configure `ledger-mode' to auto-align postings."
|
"Configure `ledger-mode' to auto-align postings."
|
||||||
(if ledger-post-auto-adjust-amounts
|
(add-hook 'after-change-functions 'ledger-post-maybe-align t t)
|
||||||
(add-hook 'after-change-functions 'ledger-post-maybe-align t t))
|
|
||||||
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil))))
|
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,11 @@ reconcile-finish will mark all pending posting cleared."
|
||||||
(account ledger-acct)
|
(account ledger-acct)
|
||||||
(val nil))
|
(val nil))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
;; note that in the line below, the --format option is
|
||||||
|
;; separated from the actual format string. emacs does not
|
||||||
|
;; split arguments like the shell does, so you need to
|
||||||
|
;; specify the individual fields in the command line.
|
||||||
(ledger-exec-ledger buffer (current-buffer)
|
(ledger-exec-ledger buffer (current-buffer)
|
||||||
; note that in the line below, the --format option is
|
|
||||||
; separated from the actual format string. emacs does not
|
|
||||||
; split arguments like the shell does, so you need to
|
|
||||||
; specify the individual fields in the command line.
|
|
||||||
"balance" "--limit" "cleared or pending" "--empty"
|
"balance" "--limit" "cleared or pending" "--empty"
|
||||||
"--format" "%(display_total)" account)
|
"--format" "%(display_total)" account)
|
||||||
(setq val
|
(setq val
|
||||||
|
|
@ -82,8 +82,8 @@ reconcile-finish will mark all pending posting cleared."
|
||||||
(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 balnce and calculate the
|
"Display the cleared-or-pending balance.
|
||||||
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))
|
||||||
(target-delta (if ledger-target
|
(target-delta (if ledger-target
|
||||||
|
|
@ -111,7 +111,7 @@ target-delta of the account being reconciled."
|
||||||
"Return a buffer from WHERE the transaction is."
|
"Return a buffer from WHERE the transaction is."
|
||||||
(if (bufferp (car where))
|
(if (bufferp (car where))
|
||||||
(car where)
|
(car where)
|
||||||
(error "ledger-reconcile-get-buffer: Buffer not set")))
|
(error "Function ledger-reconcile-get-buffer: Buffer not set")))
|
||||||
|
|
||||||
(defun ledger-reconcile-toggle ()
|
(defun ledger-reconcile-toggle ()
|
||||||
"Toggle the current transaction, and mark the recon window."
|
"Toggle the current transaction, and mark the recon window."
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,10 @@ dropped."
|
||||||
|
|
||||||
;;this excursion toggles the posting status
|
;;this excursion toggles the posting status
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
(let ((has-align-hook (remove-hook
|
||||||
|
'after-change-functions
|
||||||
|
'ledger-post-maybe-align t)))
|
||||||
|
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
(when (looking-at "[ \t]")
|
(when (looking-at "[ \t]")
|
||||||
(skip-chars-forward " \t")
|
(skip-chars-forward " \t")
|
||||||
|
|
@ -157,7 +161,9 @@ dropped."
|
||||||
(delete-char 2))
|
(delete-char 2))
|
||||||
((looking-at " ")
|
((looking-at " ")
|
||||||
(delete-char 1))))
|
(delete-char 1))))
|
||||||
(setq new-status inserted)))))
|
(setq new-status inserted))))
|
||||||
|
(if has-align-hook
|
||||||
|
(add-hook 'after-change-functions 'ledger-post-maybe-align t t))))
|
||||||
|
|
||||||
;; This excursion cleans up the entry so that it displays
|
;; This excursion cleans up the entry so that it displays
|
||||||
;; minimally. This means that if all posts are cleared, remove
|
;; minimally. This means that if all posts are cleared, remove
|
||||||
|
|
@ -254,6 +260,4 @@ dropped."
|
||||||
|
|
||||||
(provide 'ldg-state)
|
(provide 'ldg-state)
|
||||||
|
|
||||||
(provide 'ldg-state)
|
|
||||||
|
|
||||||
;;; ldg-state.el ends here
|
;;; ldg-state.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue