diff options
author | Craig Earls <enderw88@gmail.com> | 2013-03-25 21:19:17 -0400 |
---|---|---|
committer | Craig Earls <enderw88@gmail.com> | 2013-03-25 21:19:17 -0400 |
commit | bc7a885eb711f4a6cf83d8e7701d90f0079e0359 (patch) | |
tree | 4cd138c0a1b0f04b7f15dab972376208af540ad3 /lisp/ldg-post.el | |
parent | 48266d110758e54716177e5c87e33103247414a0 (diff) | |
download | fork-ledger-bc7a885eb711f4a6cf83d8e7701d90f0079e0359.tar.gz fork-ledger-bc7a885eb711f4a6cf83d8e7701d90f0079e0359.tar.bz2 fork-ledger-bc7a885eb711f4a6cf83d8e7701d90f0079e0359.zip |
Speed improvement to align-postings.
In some cases align-posting was getting called twice
Diffstat (limited to 'lisp/ldg-post.el')
-rw-r--r-- | lisp/ldg-post.el | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index 75efb83c..5ac97893 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -158,10 +158,10 @@ position, whichever is closer." (copy-marker end) end))) -(defun ledger-post-adjust (adjust-by) +(defsubst ledger-post-adjust (adjust-by) (if (> adjust-by 0) (insert (make-string adjust-by ? )) - (if (looking-back " " (- (point) 3)) + (if (looking-back " " (- (point) 1)) (delete-char adjust-by) (skip-chars-forward "^ \t") (delete-horizontal-space) @@ -176,7 +176,10 @@ region align the posting on the current line." (not (use-region-p))) (set-mark (point))) - (let* ((mark-first (< (mark) (point))) + (let* ((has-align-hook (remove-hook + 'after-change-functions + 'ledger-post-maybe-align t)) + (mark-first (< (mark) (point))) (begin-region (if beg beg (if mark-first (mark) (point)))) @@ -204,7 +207,9 @@ region align the posting on the current line." (current-column)))) (if (/= amt-adjust 0) (ledger-post-adjust amt-adjust))))) - (forward-line))))) + (forward-line)) + (if has-align-hook + (add-hook 'after-change-functions 'ledger-post-maybe-align t t))))) (defun ledger-post-maybe-align (beg end len) "Align amounts only if point is in a posting. |