diff options
author | Craig Earls <enderw88@gmail.com> | 2013-03-18 15:05:54 -0700 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-03-18 15:05:54 -0700 |
commit | 5df242424ab507ca51b7b98c85cde594549510c6 (patch) | |
tree | dc202f1a01a8e2eb686baa126ce9ca175fc4f960 /lisp/ldg-post.el | |
parent | 8d73979abf87e3910bd040fb4b549b7d4c98a8c2 (diff) | |
download | fork-ledger-5df242424ab507ca51b7b98c85cde594549510c6.tar.gz fork-ledger-5df242424ab507ca51b7b98c85cde594549510c6.tar.bz2 fork-ledger-5df242424ab507ca51b7b98c85cde594549510c6.zip |
Bug 916: Added back in old ledger-post-align-amount code for Thierry.
Diffstat (limited to 'lisp/ldg-post.el')
-rw-r--r-- | lisp/ldg-post.el | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index c871df28..d37b2f51 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -173,6 +173,55 @@ the account" (goto-char (1+ (line-end-position))) (ledger-post-align-postings))) +;; +;; This is the orignal ledger align amount code it does not attempt to format accounts +;; + + +(defun ledger-align-amounts (&optional column) + "Align amounts and accounts in the current region. +This is done so that the last digit falls in COLUMN, which +defaults to 52. ledger-default-acct-transaction-indent positions +the account" + (interactive "p") + (if (or (null column) (= column 1)) + (setq column ledger-post-amount-alignment-column)) + (save-excursion + ;; Position the account + ;; (beginning-of-line) + (set-mark (point)) + ;; (delete-horizontal-space) + ;; (insert ledger-default-acct-transaction-indent) + (goto-char (1+ (line-end-position))) + (let* ((mark-first (< (mark) (point))) + (begin (if mark-first (mark) (point))) + (end (if mark-first (point-marker) (mark-marker))) + offset) + ;; Position the amount + (goto-char begin) + (while (setq offset (ledger-next-amount end)) + (let ((col (current-column)) + (target-col (- column offset)) + adjust) + (setq adjust (- target-col col)) + (if (< col target-col) + (insert (make-string (- target-col col) ? )) + (move-to-column target-col) + (if (looking-back " ") + (delete-char (- col target-col)) + (skip-chars-forward "^ \t") + (delete-horizontal-space) + (insert " "))) + (forward-line)))))) + +(defun ledger-post-align-amount () + "Align the amounts in this posting." + (interactive) + (save-excursion + (set-mark (line-beginning-position)) + (goto-char (1+ (line-end-position))) + (ledger-align-amounts))) + (defun ledger-post-maybe-align (beg end len) "Align amounts only if point is in a posting. BEG, END, and LEN control how far it can align." |