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)))
|
nil)))
|
||||||
(ledger-read-string-with-default prompt default)))
|
(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)
|
(defun ledger-read-string-with-default (prompt default)
|
||||||
"Return user supplied string after PROMPT, or DEFAULT."
|
"Return user supplied string after PROMPT, or DEFAULT."
|
||||||
(read-string (concat prompt
|
(read-string (concat prompt
|
||||||
|
|
@ -173,22 +185,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
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,11 @@ reconcile-finish will mark all pending posting cleared."
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'ledger-reconcile)
|
: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)
|
(defun ledger-reconcile-get-cleared-or-pending-balance (buffer account)
|
||||||
"Calculate the cleared or pending balance of the 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)
|
(forward-char)
|
||||||
(setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending
|
(setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending
|
||||||
'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 the existing face and add the new face
|
||||||
(remove-text-properties (line-beginning-position)
|
(remove-text-properties (line-beginning-position)
|
||||||
(line-end-position)
|
(line-end-position)
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,7 @@ MOMENT is an encoded date"
|
||||||
(defun ledger-copy-transaction-at-point (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."
|
"Ask for a new DATE and copy the transaction under point to that date. Leave point on the first amount."
|
||||||
(interactive (list
|
(interactive (list
|
||||||
(read-string "Copy to date: " (ledger-year-and-month)
|
(ledger-read-date "Copy to date: ")))
|
||||||
'ledger-minibuffer-history)))
|
|
||||||
(let* ((here (point))
|
(let* ((here (point))
|
||||||
(extents (ledger-find-xact-extents (point)))
|
(extents (ledger-find-xact-extents (point)))
|
||||||
(transaction (buffer-substring-no-properties (car extents) (cadr extents)))
|
(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
|
there, otherwise call `ledger-xact-find-slot' to insert it at the
|
||||||
correct chronological place in the buffer."
|
correct chronological place in the buffer."
|
||||||
(interactive (list
|
(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
|
(let* ((args (with-temp-buffer
|
||||||
(insert transaction-text)
|
(insert transaction-text)
|
||||||
(eshell-parse-arguments (point-min) (point-max))))
|
(eshell-parse-arguments (point-min) (point-max))))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue