Improve `ledger-insert-effective-date'.
The function now replaces already existing effective dates in the same line. With a prefix (C-u C-c C-t), remove the current effective date. Signed-off-by: Moritz Ulrich <moritz@tarn-vedra.de>
This commit is contained in:
parent
6dbb36f525
commit
7dd82f8bac
1 changed files with 27 additions and 10 deletions
|
|
@ -168,16 +168,33 @@ Can indent, complete or align depending on context."
|
||||||
nil 'noerr)
|
nil 'noerr)
|
||||||
(replace-match ""))))))))
|
(replace-match ""))))))))
|
||||||
|
|
||||||
(defun ledger-insert-effective-date ()
|
(defun ledger-insert-effective-date (&optional arg)
|
||||||
(interactive)
|
"Insert an effective date to the transaction or posting.
|
||||||
|
|
||||||
|
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)))
|
||||||
|
(ledger-remove-effective-date)
|
||||||
(let ((context (car (ledger-context-at-point)))
|
(let ((context (car (ledger-context-at-point)))
|
||||||
(date-string (format-time-string (cdr (assoc "date-format" ledger-environment-alist)))))
|
(date-string (format-time-string
|
||||||
(cond ((eq 'xact context)
|
(cdr (assoc "date-format" ledger-environment-alist)))))
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region (point-at-bol) (point-at-eol))
|
||||||
|
(cond
|
||||||
|
((eq 'xact context)
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(insert date-string "="))
|
(re-search-forward ledger-iso-date-regexp)
|
||||||
|
(when (= (char-after) ?=)
|
||||||
|
(ledger-remove-effective-date))
|
||||||
|
(insert "=" date-string))
|
||||||
((eq 'acct-transaction context)
|
((eq 'acct-transaction context)
|
||||||
(end-of-line)
|
(end-of-line)
|
||||||
(insert " ; [=" date-string "]")))))
|
(ledger-remove-effective-date)
|
||||||
|
(insert " ; [=" date-string "]")))))))
|
||||||
|
|
||||||
(defun ledger-mode-remove-extra-lines ()
|
(defun ledger-mode-remove-extra-lines ()
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue