diff options
author | Craig Earls <enderw88@gmail.com> | 2013-03-27 20:02:59 -0700 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-03-27 20:02:59 -0700 |
commit | 12b2d1b6281166c863f0270220cc5a9d448130ca (patch) | |
tree | 14c4056501462c3030285b2ad291a0d849f129ee /lisp | |
parent | 15b1d36fa298b0eb743ee4839096899787e11b8d (diff) | |
parent | 7fea9d21fb72e1d66423a928297dd3cc29c7cc78 (diff) | |
download | fork-ledger-12b2d1b6281166c863f0270220cc5a9d448130ca.tar.gz fork-ledger-12b2d1b6281166c863f0270220cc5a9d448130ca.tar.bz2 fork-ledger-12b2d1b6281166c863f0270220cc5a9d448130ca.zip |
Merge branch 'next' into ledger-mode-automatic-transactions
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ldg-mode.el | 2 | ||||
-rw-r--r-- | lisp/ldg-post.el | 48 | ||||
-rw-r--r-- | lisp/ldg-xact.el | 2 |
3 files changed, 28 insertions, 24 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 1d587d63..c9814918 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -249,7 +249,7 @@ correct chronological place in the buffer." (insert (with-temp-buffer (setq exit-code - (apply #'ledger-exec-ledger ledger-buf ledger-buf "xact" + (apply #'ledger-exec-ledger ledger-buf (current-buffer) "xact" (mapcar 'eval args))) (goto-char (point-min)) (if (looking-at "Error: ") diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index d5646702..91ee623d 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -136,23 +136,18 @@ point at beginning of the commodity." (match-end 3)) (point)))) (defvar ledger-post-account-regex - (concat "\\(^[ \t]+\\)" - "\\([\\[(*!;a-zA-Z0-9]\\)")) + "\\(^[ \t]+\\)\\(.+?\\)\\( \\|\n\\)") -(defsubst ledger-next-account (&optional end) +(defun ledger-next-account (&optional end) "Move point to the beginning of the next account, or status marker (!*), as long as it is not past END. Return the column of the beginning of the account and leave point at beginning of account" (if (> end (point)) - (when (re-search-forward ledger-post-account-regex end t) + (when (re-search-forward ledger-post-account-regex (1+ end) t) + ;; the 1+ is to make sure we can catch the newline (goto-char (match-beginning 2)) (current-column)))) -(defsubst ledger-post-adjust (adjust-by) - (if (> adjust-by 0) - (insert (make-string adjust-by ? )) - (delete-char adjust-by))) - (defun ledger-post-align-postings (&optional beg end) "Align all accounts and amounts within region, if there is no region align the posting on the current line." @@ -179,22 +174,31 @@ region align the posting on the current line." (goto-char (setq begin-region (line-beginning-position))) - + ;; This is the guts of the alignment loop (while (and (or (setq acc-col (ledger-next-account (line-end-position))) - lines-left) - (< (point) end-region)) + lines-left) + (< (point) end-region)) (when acc-col - (if (/= (setq acc-adjust (- ledger-post-account-alignment-column acc-col)) 0) - (ledger-post-adjust acc-adjust)) - - (when (setq amt-offset (ledger-next-amount (line-end-position))) - (let* ((amt-adjust (- ledger-post-amount-alignment-column - amt-offset - (current-column)))) - (if (/= amt-adjust 0) - (ledger-post-adjust amt-adjust))))) - (forward-line) + (when (/= (setq acc-adjust (- ledger-post-account-alignment-column acc-col)) 0) + (if (> acc-adjust 0) + (insert (make-string acc-adjust ? )) + (delete-char acc-adjust))) + (when (setq amt-offset (ledger-next-amount (line-end-position))) + (let* ((amt-adjust (- ledger-post-amount-alignment-column + amt-offset + (current-column)))) + (if (/= amt-adjust 0) + (if (> amt-adjust 0) + (insert (make-string amt-adjust ? )) + (let ((curpoint (point))) + (beginning-of-line) + (ledger-next-account (line-end-position)) + (when (> (+ curpoint amt-adjust) + (match-end 2)) + (goto-char curpoint) + (delete-char amt-adjust)))))))) + (forward-line) (setq lines-left (not (eobp)))) (setq inhibit-modification-hooks nil)))) diff --git a/lisp/ldg-xact.el b/lisp/ldg-xact.el index e2180b57..d6ccc2bf 100644 --- a/lisp/ldg-xact.el +++ b/lisp/ldg-xact.el @@ -21,7 +21,7 @@ ;;; Commentary: -;; Utilites for running ledger synchronously. +;; Utilities for running ledger synchronously. ;;; Code: |