Skip to content

Commit 58fe513

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 8bad528 commit 58fe513

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 minibuffer prompt string composing PROMPT and DEFAULT."

ledger-xact.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ MOMENT is an encoded date"
151151
"Ask for a new DATE and copy the transaction under point to that date.
152152
Leave point on the first amount."
153153
(interactive (list
154-
(ledger-read-date "Copy to date: ")))
154+
(ledger-read-date "Copy to date: "
155+
(ledger-parse-iso-date
156+
(ledger-xact-date)))))
155157
(let* ((extents (ledger-navigate-find-xact-extents (point)))
156158
(transaction (buffer-substring-no-properties (car extents) (cadr extents)))
157159
(encoded-date (ledger-parse-iso-date date)))

0 commit comments

Comments
 (0)