More speed improvements for align-postings.

This commit is contained in:
Craig Earls 2013-03-26 19:34:37 -04:00
parent c8c94e9602
commit 5b1778b3ca

View file

@ -137,27 +137,17 @@ point at beginning of the commodity."
(defvar ledger-post-account-regex (defvar ledger-post-account-regex
(concat "\\(^[ \t]+\\)" (concat "\\(^[ \t]+\\)"
"\\([\\[(*!;a-zA-Z0-9]+?\\)")) "\\([\\[(*!;a-zA-Z0-9]\\)"))
(defsubst ledger-next-account (&optional end) (defsubst 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. "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 Return the column of the beginning of the account and leave point
at beginning of account" at beginning of account"
;; (beginning-of-line)
(if (> end (point)) (if (> end (point))
(when (re-search-forward ledger-post-account-regex end t) (when (re-search-forward ledger-post-account-regex end t)
(goto-char (match-beginning 2)) (goto-char (match-beginning 2))
(current-column)))) (current-column))))
(defsubst ledger-post-end-of-line-or-region (end-region)
"Return a number the END-REGION or end of line
position, whichever is closer."
(let ((eol (line-end-position)))
(if (< end-region eol)
end-region
eol)))
(defsubst ledger-post-adjust (adjust-by) (defsubst ledger-post-adjust (adjust-by)
(if (> adjust-by 0) (if (> adjust-by 0)
(insert (make-string adjust-by ? )) (insert (make-string adjust-by ? ))
@ -189,15 +179,16 @@ region align the posting on the current line."
(goto-char (goto-char
(setq begin-region (setq begin-region
(line-beginning-position))) (line-beginning-position)))
(while (or (setq acc-col (ledger-next-account (ledger-post-end-of-line-or-region end-region)))
;; This is the guts of the alignment loop
(while (or (setq acc-col (ledger-next-account (line-end-position)))
(and (< (point) end-region) (and (< (point) end-region)
lines-left)) lines-left))
(when acc-col (when acc-col
(setq acc-adjust (- ledger-post-account-alignment-column acc-col)) (if (/= (setq acc-adjust (- ledger-post-account-alignment-column acc-col)) 0)
(if (/= acc-adjust 0)
(ledger-post-adjust acc-adjust)) (ledger-post-adjust acc-adjust))
(when (setq amt-offset (ledger-next-amount (ledger-post-end-of-line-or-region end-region))) (when (setq amt-offset (ledger-next-amount (line-end-position)))
(let* ((amt-adjust (- ledger-post-amount-alignment-column (let* ((amt-adjust (- ledger-post-amount-alignment-column
amt-offset amt-offset
(current-column)))) (current-column))))