From 3a2eb94beff65f22463c119e4db55a2962ac02e0 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Wed, 25 Jun 2014 20:50:07 -0700 Subject: [PATCH] Fix bug 1052 ledger-mode mangles transactions with tabs. --- lisp/ledger-mode.el | 1 + lisp/ledger-post.el | 11 ++++++++++- lisp/ledger-state.el | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index ec1bc505..f89df45c 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -222,6 +222,7 @@ With a prefix argument, remove the effective date. " (defun ledger-mode-clean-buffer () "indent, remove multiple linfe feeds and sort the buffer" (interactive) + (untabify (point-min) (point-max)) (ledger-sort-buffer) (ledger-post-align-postings (point-min) (point-max)) (ledger-mode-remove-extra-lines)) diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el index 2709a5e3..ea718f9d 100644 --- a/lisp/ledger-post.el +++ b/lisp/ledger-post.el @@ -163,7 +163,16 @@ region align the posting on the current line." (if mark-first (point) (mark)))) acct-start-column acct-end-column acct-adjust amt-width (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) + (setq end-region (line-end-position)) + (goto-char begin-region) + (goto-char + (setq begin-region + (line-beginning-position))) + + (untabify begin-region end-region) + (goto-char end-region) (setq end-region (line-end-position)) (goto-char begin-region) diff --git a/lisp/ledger-state.el b/lisp/ledger-state.el index 53e08e22..989e6d33 100644 --- a/lisp/ledger-state.el +++ b/lisp/ledger-state.el @@ -103,9 +103,9 @@ dropped." (skip-chars-forward " \t") (when (not (eq (ledger-state-from-char (char-after)) 'comment)) (insert (ledger-char-from-state cur-status) " ") - (if (search-forward " " (line-end-position) t) - (if (looking-at " ") - (delete-char 2)))) + (if (and (search-forward " " (line-end-position) t) + (looking-at " ")) + (delete-char 2))) (forward-line)) (setq new-status nil)))