From 3ff5fddafd6bff3c0768eeae032f7eb6ab32db5b Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 2 Jan 2014 18:24:54 +0100 Subject: Add `ledger-read-date' - Read date & default to today. --- lisp/ledger-mode.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 0d683168..e18529c9 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -99,6 +99,17 @@ 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))) + (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 -- cgit v1.2.3 From 26bc890d882586e808b9def9ddf68a752b4c8e18 Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 2 Jan 2014 18:43:53 +0100 Subject: `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. --- lisp/ledger-mode.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index e18529c9..4edd745f 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -184,22 +184,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 -- cgit v1.2.3 From 09ef323a7364d7f27c44bcfdce01e9b41063284c Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 2 Jan 2014 18:44:15 +0100 Subject: ledger-reconcile: Add option to insert an effective date when clearing transactions. --- lisp/ledger-reconcile.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3 From 8406adce0ec2afd8cd933c8d5172781bded42fc8 Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 2 Jan 2014 18:55:25 +0100 Subject: `ledger-read-date': Use `ledger-minibuffer-history'. --- lisp/ledger-mode.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 4edd745f..27f8893b 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -102,7 +102,8 @@ (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))) + (date (read-string prompt default + 'ledger-minibuffer-history))) (if (or (string= date default) (string= "" date)) (format-time-string -- cgit v1.2.3 From 741a275cc99f73521e9588798a21f62aebf7fa7c Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 2 Jan 2014 19:00:37 +0100 Subject: Use `ledger-read-date' where applicable. --- lisp/ledger-xact.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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)))) -- cgit v1.2.3