From 48266d110758e54716177e5c87e33103247414a0 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Mon, 25 Mar 2013 18:48:28 -0400 Subject: Fix bug 928 Refix slow indent-region behavior. Need to bing ledger-post-align-postings to indent-region-function, not indent-line-function, others it tries to align the entire region once for every line in the region. --- lisp/ldg-mode.el | 2 +- lisp/ldg-post.el | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index b435ada2..1d587d63 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -92,7 +92,7 @@ Can be pcomplete, or align-posting" (ledger-init-load-init-file) - (setq indent-line-function 'ledger-post-align-postings) + (setq indent-region-function 'ledger-post-align-postings) (let ((map (current-local-map))) (define-key map [(control ?c) (control ?a)] 'ledger-add-transaction) diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el index c831f01a..75efb83c 100644 --- a/lisp/ldg-post.el +++ b/lisp/ldg-post.el @@ -167,17 +167,22 @@ position, whichever is closer." (delete-horizontal-space) (insert " ")))) -(defun ledger-post-align-postings () +(defun ledger-post-align-postings (&optional beg end) "Align all accounts and amounts within region, if there is no -region alight the posting on the current line." +region align the posting on the current line." (interactive) (save-excursion (if (or (not (mark)) (not (use-region-p))) (set-mark (point))) + (let* ((mark-first (< (mark) (point))) - (begin-region (if mark-first (mark) (point))) - (end-region (if mark-first (point-marker) (mark-marker))) + (begin-region (if beg + beg + (if mark-first (mark) (point)))) + (end-region (if end + end + (if mark-first (point-marker) (mark-marker)))) acc-col amt-offset acc-adjust) ;; Condition point and mark to the beginning and end of lines (goto-char end-region) -- cgit v1.2.3