From 4ca0e8916b5a821a4659918a754427799b5b9036 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 27 Mar 2013 15:37:52 -0700 Subject: Fix bug 935, very long account names can get stomped on. This works, but hammers performance --- lisp/ldg-post.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lisp/ldg-post.el') diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index d5646702..f2adc676 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -136,17 +136,16 @@ point at beginning of the commodity." (match-end 3)) (point)))) (defvar ledger-post-account-regex - (concat "\\(^[ \t]+\\)" - "\\([\\[(*!;a-zA-Z0-9]\\)")) + "\\(^[ \t]+\\)\\([\\[(;!*A-Za-z0-9]\\)\\(.+?\\)\\( \\|\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) (goto-char (match-beginning 2)) - (current-column)))) + (list (current-column) (length (match-string-no-properties 3)))))) (defsubst ledger-post-adjust (adjust-by) (if (> adjust-by 0) @@ -185,10 +184,12 @@ region align the posting on the current line." lines-left) (< (point) end-region)) (when acc-col - (if (/= (setq acc-adjust (- ledger-post-account-alignment-column acc-col)) 0) + (if (/= (setq acc-adjust (- ledger-post-account-alignment-column (car acc-col))) 0) (ledger-post-adjust acc-adjust)) - (when (setq amt-offset (ledger-next-amount (line-end-position))) + (when (and + (> ledger-post-amount-alignment-column (+ ledger-post-account-alignment-column (cadr acc-col))) + (setq amt-offset (ledger-next-amount (line-end-position)))) (let* ((amt-adjust (- ledger-post-amount-alignment-column amt-offset (current-column)))) -- cgit v1.2.3 From 7fea9d21fb72e1d66423a928297dd3cc29c7cc78 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 27 Mar 2013 20:02:11 -0700 Subject: Align post speed improvements after adding the long account name handling. --- lisp/ldg-post.el | 49 ++++++++++++++++++++++++++----------------------- lisp/ldg-xact.el | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) (limited to 'lisp/ldg-post.el') diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index f2adc676..91ee623d 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -136,21 +136,17 @@ point at beginning of the commodity." (match-end 3)) (point)))) (defvar ledger-post-account-regex - "\\(^[ \t]+\\)\\([\\[(;!*A-Za-z0-9]\\)\\(.+?\\)\\( \\|\n\\)") + "\\(^[ \t]+\\)\\(.+?\\)\\( \\|\n\\)") (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 (1+ 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)) - (list (current-column) (length (match-string-no-properties 3)))))) - -(defsubst ledger-post-adjust (adjust-by) - (if (> adjust-by 0) - (insert (make-string adjust-by ? )) - (delete-char adjust-by))) + (current-column)))) (defun ledger-post-align-postings (&optional beg end) "Align all accounts and amounts within region, if there is no @@ -178,24 +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 (car acc-col))) 0) - (ledger-post-adjust acc-adjust)) - - (when (and - (> ledger-post-amount-alignment-column (+ ledger-post-account-alignment-column (cadr acc-col))) - (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: -- cgit v1.2.3