summaryrefslogtreecommitdiff
path: root/lisp/ledger-mode.el
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2014-01-02 10:09:23 -0800
committerCraig Earls <enderw88@gmail.com>2014-01-02 10:09:23 -0800
commitbde5e69c9acf54e0d9f6eec7f380a15f82d3102e (patch)
treee6f03a43fb5c9b33052be54147abca9ac0635c15 /lisp/ledger-mode.el
parent876cfa1f78d4c036332f3d918a88817fe72353e4 (diff)
parent741a275cc99f73521e9588798a21f62aebf7fa7c (diff)
downloadfork-ledger-bde5e69c9acf54e0d9f6eec7f380a15f82d3102e.tar.gz
fork-ledger-bde5e69c9acf54e0d9f6eec7f380a15f82d3102e.tar.bz2
fork-ledger-bde5e69c9acf54e0d9f6eec7f380a15f82d3102e.zip
Merge pull request #228 from the-kenny/emacs-prompt-effective-date
Emacs: Improve effictive-date-handling
Diffstat (limited to 'lisp/ledger-mode.el')
-rw-r--r--lisp/ledger-mode.el29
1 files changed, 20 insertions, 9 deletions
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el
index 0d683168..27f8893b 100644
--- a/lisp/ledger-mode.el
+++ b/lisp/ledger-mode.el
@@ -99,6 +99,18 @@
nil)))
(ledger-read-string-with-default prompt default)))
+(defun ledger-read-date (prompt)
+ "Returns user-supplied date after `PROMPT', defaults to today."
+ (let* ((default (ledger-year-and-month))
+ (date (read-string prompt default
+ 'ledger-minibuffer-history)))
+ (if (or (string= date default)
+ (string= "" date))
+ (format-time-string
+ (or (cdr (assoc "date-format" ledger-environment-alist))
+ ledger-default-date-format))
+ date)))
+
(defun ledger-read-string-with-default (prompt default)
"Return user supplied string after PROMPT, or DEFAULT."
(read-string (concat prompt
@@ -173,22 +185,21 @@ Can indent, complete or align depending on context."
nil 'noerr)
(replace-match ""))))))))
-(defun ledger-insert-effective-date (&optional arg)
- "Insert an effective date to the transaction or posting.
+(defun ledger-insert-effective-date (&optional date)
+ "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
line.
With a prefix argument, remove the effective date. "
- (interactive "P")
- (if (and (listp arg)
- (= 4 (prefix-numeric-value arg)))
+ (interactive)
+ (if (and (listp current-prefix-arg)
+ (= 4 (prefix-numeric-value current-prefix-arg)))
(ledger-remove-effective-date)
(let* ((context (car (ledger-context-at-point)))
- (date-format (or
- (cdr (assoc "date-format" ledger-environment-alist))
- ledger-default-date-format))
- (date-string (format-time-string date-format)))
+ (date-string (or date (ledger-read-date "Effective date: "))))
(save-restriction
(narrow-to-region (point-at-bol) (point-at-eol))
(cond