Rewrote align-postings again to improve handling of long account-names. It now leaves exactly 2 space between the commodity and the account if the amount would have stomped on the account.

This commit is contained in:
Craig Earls 2013-04-05 23:18:24 -07:00
parent a373f9f4e5
commit 5165b19d07

View file

@ -160,7 +160,7 @@ region align the posting on the current line."
(end-region (if end (end-region (if end
end end
(if mark-first (point) (mark)))) (if mark-first (point) (mark))))
acc-col amt-offset acc-adjust acct-start-column amt-width acct-adjust acct-end-column
(lines-left 1)) (lines-left 1))
;; Condition point and mark to the beginning and end of lines ;; Condition point and mark to the beginning and end of lines
(goto-char end-region) (goto-char end-region)
@ -171,29 +171,30 @@ region align the posting on the current line."
(line-beginning-position))) (line-beginning-position)))
;; This is the guts of the alignment loop ;; This is the guts of the alignment loop
(while (and (or (setq acc-col (ledger-next-account (line-end-position))) (while (and (or (setq acct-start-column (ledger-next-account (line-end-position)))
lines-left) lines-left)
(< (point) end-region)) (< (point) end-region))
(when acc-col (when acct-start-column
(when (/= (setq acc-adjust (- ledger-post-account-alignment-column acc-col)) 0) (setq acct-end-column (save-excursion
(if (> acc-adjust 0) (goto-char (match-end 2))
(insert (make-string acc-adjust ? )) (current-column)))
(delete-char acc-adjust))) (when (/= (setq acct-adjust (- ledger-post-account-alignment-column acct-start-column)) 0)
(when (setq amt-offset (ledger-next-amount (line-end-position))) (setq acct-end-column (+ acct-end-column acct-adjust))
(let* ((amt-adjust (- ledger-post-amount-alignment-column (if (> acct-adjust 0)
amt-offset (insert (make-string acct-adjust ? ))
(current-column) (delete-char acct-adjust)))
2))) (when (setq amt-width (ledger-next-amount (line-end-position)))
(let ((amt-adjust (- (if (> (- ledger-post-amount-alignment-column amt-width)
(+ 2 acct-end-column))
ledger-post-amount-alignment-column
(+ acct-end-column
2 amt-width))
amt-width
(current-column))))
(if (/= amt-adjust 0) (if (/= amt-adjust 0)
(if (> amt-adjust 0) (if (> amt-adjust 0)
(insert (make-string amt-adjust ? )) (insert (make-string amt-adjust ? ))
(let ((curpoint (point))) (delete-char amt-adjust))))))
(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) (forward-line)
(setq lines-left (not (eobp)))) (setq lines-left (not (eobp))))
(setq inhibit-modification-hooks nil)))) (setq inhibit-modification-hooks nil))))