Merge pull request #228 from the-kenny/emacs-prompt-effective-date
Emacs: Improve effictive-date-handling
This commit is contained in:
commit
bde5e69c9a
3 changed files with 33 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue