summaryrefslogtreecommitdiff
path: root/lisp
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
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')
-rw-r--r--lisp/ledger-mode.el29
-rw-r--r--lisp/ledger-reconcile.el10
-rw-r--r--lisp/ledger-xact.el7
3 files changed, 33 insertions, 13 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
diff --git a/lisp/ledger-reconcile.el b/lisp/ledger-reconcile.el
index 44e60532..47f0e176 100644
--- a/lisp/ledger-reconcile.el
+++ b/lisp/ledger-reconcile.el
@@ -80,6 +80,11 @@ reconcile-finish will mark all pending posting cleared."
:type 'string
:group 'ledger-reconcile)
+(defcustom ledger-reconcile-insert-effective-date nil
+ "If t, prompt for effective date when clearing transactions during reconciliation."
+ :type 'boolean
+ :group 'ledger-reconcile)
+
(defun ledger-reconcile-get-cleared-or-pending-balance (buffer account)
"Calculate the cleared or pending balance of the account."
@@ -136,7 +141,10 @@ And calculate the target-delta of the account being reconciled."
(forward-char)
(setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending
'pending
- 'cleared))))
+ 'cleared)))
+ (when ledger-reconcile-insert-effective-date
+ ;; Ask for effective date & insert it
+ (ledger-insert-effective-date)))
;; remove the existing face and add the new face
(remove-text-properties (line-beginning-position)
(line-end-position)
diff --git a/lisp/ledger-xact.el b/lisp/ledger-xact.el
index f65e5ed6..db642605 100644
--- a/lisp/ledger-xact.el
+++ b/lisp/ledger-xact.el
@@ -135,8 +135,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."
(interactive (list
- (read-string "Copy to date: " (ledger-year-and-month)
- 'ledger-minibuffer-history)))
+ (ledger-read-date "Copy to date: ")))
(let* ((here (point))
(extents (ledger-find-xact-extents (point)))
(transaction (buffer-substring-no-properties (car extents) (cadr extents)))
@@ -167,7 +166,9 @@ If INSERT-AT-POINT is non-nil insert the transaction
there, otherwise call `ledger-xact-find-slot' to insert it at the
correct chronological place in the buffer."
(interactive (list
- (read-string "Transaction: " (ledger-year-and-month))))
+ ;; Note: This isn't "just" the date - it can contain
+ ;; other text too
+ (ledger-read-date "Transaction: ")))
(let* ((args (with-temp-buffer
(insert transaction-text)
(eshell-parse-arguments (point-min) (point-max))))