diff options
Diffstat (limited to 'lisp/ldg-post.el')
-rw-r--r-- | lisp/ldg-post.el | 66 |
1 files changed, 10 insertions, 56 deletions
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index d37b2f51..3313c8e3 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -123,8 +123,8 @@ PROMPT is a string to prompt with. CHOICES is a list of (- (or (match-end 4) (match-end 3)) (point)))) -(defun ledger-post-align-postings (&optional column) - "Align amounts and accounts in the current region. +(defun ledger-post-align-posting (&optional column) + "Align amounts and accounts in the current posting. This is done so that the last digit falls in COLUMN, which defaults to 52. ledger-post-account-column positions the account" @@ -165,62 +165,16 @@ the account" (insert " "))) (forward-line)))))) -(defun ledger-post-align-posting () - "Align the amounts in this posting." - (interactive) - (save-excursion - (set-mark (line-beginning-position)) - (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)) +(defun ledger-post-align-region (beg end) + (interactive "r") (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)))))) + (goto-char beg) + (backward-paragraph) ;; make sure we are at the beginning of an xact + (while (< (point) end) + (ledger-post-align-posting) + (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. @@ -231,7 +185,7 @@ BEG, END, and LEN control how far it can align." (when (<= end (line-end-position)) (goto-char (line-beginning-position)) (if (looking-at ledger-post-line-regexp) - (ledger-post-align-postings)))))) + (ledger-post-align-posting)))))) (defun ledger-post-edit-amount () "Call 'calc-mode' and push the amount in the posting to the top of stack." |