ledger-insert-effective-date': use ledger-read-date'.

Running `ledger-insert-effective-date' will now prompt for a date with
a pre-filled value of the `(ledger-year-and-month)' ("2014/01/"). Just
pressing RET without inserting the 'day'-portion will insert the date
of today.
This commit is contained in:
Moritz Ulrich 2014-01-02 18:43:53 +01:00
parent 3ff5fddafd
commit 26bc890d88

View file

@ -184,22 +184,21 @@ Can indent, complete or align depending on context."
nil 'noerr) nil 'noerr)
(replace-match "")))))))) (replace-match ""))))))))
(defun ledger-insert-effective-date (&optional arg) (defun ledger-insert-effective-date (&optional date)
"Insert an effective date to the transaction or posting. "Insert effective date `DATE' to the transaction or posting.
If `DATE' is nil, prompt the user a date.
Replace the current effective date if there's one in the same Replace the current effective date if there's one in the same
line. line.
With a prefix argument, remove the effective date. " With a prefix argument, remove the effective date. "
(interactive "P") (interactive)
(if (and (listp arg) (if (and (listp current-prefix-arg)
(= 4 (prefix-numeric-value arg))) (= 4 (prefix-numeric-value current-prefix-arg)))
(ledger-remove-effective-date) (ledger-remove-effective-date)
(let* ((context (car (ledger-context-at-point))) (let* ((context (car (ledger-context-at-point)))
(date-format (or (date-string (or date (ledger-read-date "Effective date: "))))
(cdr (assoc "date-format" ledger-environment-alist))
ledger-default-date-format))
(date-string (format-time-string date-format)))
(save-restriction (save-restriction
(narrow-to-region (point-at-bol) (point-at-eol)) (narrow-to-region (point-at-bol) (point-at-eol))
(cond (cond