Bug 893 Ledger reconcile loses alignment

An earlier change to multi-file support stored the actual markers to the beginnings of the transaction/postings.
When reconcile would insert characters it would invalidate those marker and after many items and been
cleared could result in severe misalignment.  This change brings back storing the line-numbers as reported by emacs.
This commit is contained in:
Craig Earls 2013-02-13 13:23:04 -07:00
parent 6315c60e43
commit 15d838d1f8
2 changed files with 15 additions and 15 deletions

View file

@ -60,11 +60,11 @@
(let ((buffer ledger-buf) (let ((buffer ledger-buf)
(account ledger-acct)) (account ledger-acct))
(with-temp-buffer (with-temp-buffer
(ledger-exec-ledger buffer (current-buffer) "-C" "balance" account) (ledger-exec-ledger buffer (current-buffer) "balance" "--limit" "cleared or pending" account)
(goto-char (1- (point-max))) (goto-char (1- (point-max)))
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(delete-horizontal-space) (delete-horizontal-space)
(message "Cleared balance = %s" (message "Current pending balance = %s"
(buffer-substring-no-properties (point) (buffer-substring-no-properties (point)
(line-end-position)))))) (line-end-position))))))
@ -87,7 +87,8 @@
status) status)
(when (ledger-reconcile-get-buffer where) (when (ledger-reconcile-get-buffer where)
(with-current-buffer (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where)
(goto-char (cdr where)) (ledger-goto-line (cdr where))
(forward-char)
(setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending
'pending 'pending
'cleared)))) 'cleared))))
@ -139,7 +140,7 @@
(let ((where (get-text-property (point) 'where))) (let ((where (get-text-property (point) 'where)))
(when (ledger-reconcile-get-buffer where) (when (ledger-reconcile-get-buffer where)
(with-current-buffer (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where)
(goto-char (cdr where)) (ledger-goto-line (cdr where))
(ledger-delete-current-transaction)) (ledger-delete-current-transaction))
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
@ -157,7 +158,8 @@
(cur-buf (get-buffer ledger-recon-buffer-name))) (cur-buf (get-buffer ledger-recon-buffer-name)))
(when target-buffer (when target-buffer
(switch-to-buffer-other-window target-buffer) (switch-to-buffer-other-window target-buffer)
(goto-char (cdr where)) (ledger-goto-line (cdr where))
(forward-char)
(recenter) (recenter)
(ledger-highlight-xact-under-point) (ledger-highlight-xact-under-point)
(if come-back (if come-back
@ -183,7 +185,7 @@
(face (get-text-property (point) 'face))) (face (get-text-property (point) 'face)))
(if (eq face 'ledger-font-reconciler-pending-face) (if (eq face 'ledger-font-reconciler-pending-face)
(with-current-buffer (ledger-reconcile-get-buffer where) (with-current-buffer (ledger-reconcile-get-buffer where)
(goto-char (cdr where)) (ledger-goto-line (cdr where))
(ledger-toggle-current 'cleared)))) (ledger-toggle-current 'cleared))))
(forward-line 1))) (forward-line 1)))
(ledger-reconcile-save)) (ledger-reconcile-save))
@ -217,15 +219,11 @@
(let ((buf (if (is-stdin (nth 0 emacs-xact)) (let ((buf (if (is-stdin (nth 0 emacs-xact))
ledger-buf ledger-buf
(find-file-noselect (nth 0 emacs-xact))))) (find-file-noselect (nth 0 emacs-xact)))))
(with-current-buffer buf
(cons (cons
buf buf
(save-excursion
(if ledger-clear-whole-transactions (if ledger-clear-whole-transactions
(goto-line (nth 1 emacs-xact)) (nth 1 emacs-xact) ;; return line-no of xact
(goto-line (nth 0 posting))) (nth 0 posting))))) ;; return line-no of posting
(1+ (point-marker))))))) ;;Add 1 to make sure the marker is
;;within the transaction
(defun ledger-do-reconcile () (defun ledger-do-reconcile ()
"get the uncleared transactions in the account and display them "get the uncleared transactions in the account and display them

View file

@ -74,5 +74,7 @@
(ledger-context-field-value context-info 'payee) (ledger-context-field-value context-info 'payee)
nil)))) nil))))
(defsubst ledger-goto-line (line-number)
(goto-char (point-min)) (forward-line (1- line-number)))
(provide 'ldg-xact) (provide 'ldg-xact)