Skip to content

Commit

Permalink
ledger-copy-transaction-at-point: Handle transaction with no amounts
Browse files Browse the repository at this point in the history
This fixes a bug where ledger-next-amount might move point to some other
transaction, rather than the one we just copied.  Also, remove a redundant check
for the return value of re-search-forward, since it is not being used (it always
returns non-nil, or errors, if the NOERROR argument is omitted).
  • Loading branch information
bcc32 committed Apr 23, 2024
1 parent fc225f9 commit 08b87f0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ledger-xact.el
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ MOMENT is an encoded date"

(defun ledger-copy-transaction-at-point (date)
"Ask for a new DATE and copy the transaction under point to that date.
Leave point on the first amount."
Leave point on the first amount, if any, otherwise the first account."
(interactive (list (ledger-read-date "Copy to date: ")))
(let* ((extents (ledger-navigate-find-xact-extents (point)))
(transaction (buffer-substring-no-properties (car extents) (cadr extents)))
Expand All @@ -153,11 +153,14 @@ Leave point on the first amount."
"\n"))
(beginning-of-line -1)
(ledger-navigate-beginning-of-xact)
(re-search-forward ledger-iso-date-regexp)
(replace-match date)
(ledger-next-amount)
(if (re-search-forward "[-0-9]")
(goto-char (match-beginning 0)))))
(let ((end (save-excursion (ledger-navigate-end-of-xact) (point))))
(re-search-forward ledger-iso-date-regexp)
(replace-match date)
(if (ledger-next-amount end)
(progn
(re-search-forward "[-0-9]")
(goto-char (match-beginning 0)))
(ledger-next-account end)))))

(defun ledger-delete-current-transaction (pos)
"Delete the transaction surrounding POS."
Expand Down

0 comments on commit 08b87f0

Please sign in to comment.