diff options
author | Craig Earls <enderw88@gmail.com> | 2013-03-22 20:56:19 -0700 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-03-22 20:56:19 -0700 |
commit | 0d9250dbe49b62e4e340d8ac8fee84b4e9bfa57d (patch) | |
tree | db57838e99fed7ca1ea20bc8f8c8c69e56150c3a | |
parent | 75ba85ff8efc8226261203d7af063c9be3d0c034 (diff) | |
download | fork-ledger-0d9250dbe49b62e4e340d8ac8fee84b4e9bfa57d.tar.gz fork-ledger-0d9250dbe49b62e4e340d8ac8fee84b4e9bfa57d.tar.bz2 fork-ledger-0d9250dbe49b62e4e340d8ac8fee84b4e9bfa57d.zip |
Fix bug 916 along amount in region
-rw-r--r-- | lisp/ldg-mode.el | 1 | ||||
-rw-r--r-- | lisp/ldg-post.el | 66 | ||||
-rw-r--r-- | lisp/ldg-sort.el | 2 |
3 files changed, 12 insertions, 57 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 97662aa3..be825ddb 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -120,6 +120,7 @@ (define-key map [sort-start] '(menu-item "Mark Sort Beginning" ledger-sort-insert-start-mark)) (define-key map [sort-buff] '(menu-item "Sort Buffer" ledger-sort-buffer)) (define-key map [sort-reg] '(menu-item "Sort Region" ledger-sort-region :enable mark-active)) + (define-key map [align-reg] '(menu-item "Align Region" ledger-post-align-region :enable mark-active)) (define-key map [sep2] '(menu-item "--")) (define-key map [copy-xact] '(menu-item "Copy Trans at Point" ledger-copy-transaction)) (define-key map [toggle-post] '(menu-item "Toggle Current Posting" ledger-toggle-current)) 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." diff --git a/lisp/ldg-sort.el b/lisp/ldg-sort.el index 01d8edc9..3ce429fc 100644 --- a/lisp/ldg-sort.el +++ b/lisp/ldg-sort.el @@ -76,7 +76,7 @@ (new-end end)) (save-excursion (save-restriction - (goto-char beg) + (goto-char beg) (ledger-next-record-function) ;; make sure point is at the ;; beginning of a xact (setq new-beg (point)) |