Skip to content

Commit 65b7fcf

Browse files
committed
feat(xact): add default time when copying transaction
Use the transaction's time as default time when asking when the copy should be created. This allows us to use the relative syntax of org-read-date to move the transaction an <interval> forward or backward from the time of the transaction: +1d (+ 1 day from TODAY) ++1d (+ 1 day from DEFAULT-TIME, i.e. date of the original transaction) In other words, single +/- is relative against today and double ++/-- is relative against the DEFAULT-TIME. Note that since currently the DEFAULT-TIME is today, this feature is only strictly adding functionality and should therefore be fully backward-compatible.
1 parent 49d25f9 commit 65b7fcf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

ledger-mode.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@
9292
(regexp-quote account))
9393
(ledger-accounts-list))))
9494

95-
(defun ledger-read-date (prompt)
95+
(defun ledger-read-date (prompt &optional default-time)
9696
"Return user-supplied date after `PROMPT', defaults to today.
9797
This uses `org-read-date', which see."
98-
(ledger-format-date (let ((org-read-date-prefer-future nil))
99-
(org-read-date nil t nil prompt))))
98+
(ledger-format-date (let ((org-read-date-prefer-future nil)
99+
(org-extend-today-until 0))
100+
(org-read-date nil t nil prompt default-time))))
100101

101102
(defun ledger-get-minibuffer-prompt (prompt default)
102103
"Return a string composing of PROMPT and DEFAULT appropriate for a minibuffer prompt."

ledger-xact.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ MOMENT is an encoded date"
141141
(defun ledger-copy-transaction-at-point (date)
142142
"Ask for a new DATE and copy the transaction under point to that date. Leave point on the first amount."
143143
(interactive (list
144-
(ledger-read-date "Copy to date: ")))
144+
(ledger-read-date "Copy to date: "
145+
(ledger-parse-iso-date
146+
(ledger-xact-date)))))
145147
(let* ((extents (ledger-navigate-find-xact-extents (point)))
146148
(transaction (buffer-substring-no-properties (car extents) (cadr extents)))
147149
(encoded-date (ledger-parse-iso-date date)))

0 commit comments

Comments
 (0)