diff options
author | Moritz Ulrich <moritz@tarn-vedra.de> | 2013-12-30 00:50:48 +0100 |
---|---|---|
committer | Moritz Ulrich <moritz@tarn-vedra.de> | 2013-12-30 00:50:48 +0100 |
commit | 7dd82f8bacf8dfb8db42a462452c114209a72c9c (patch) | |
tree | 2a71dfa146cc4fae1fff2514015d4fb15b7a9c87 /lisp | |
parent | 6dbb36f525d1d5d35784e4f79b89d90ca1a3db93 (diff) | |
download | fork-ledger-7dd82f8bacf8dfb8db42a462452c114209a72c9c.tar.gz fork-ledger-7dd82f8bacf8dfb8db42a462452c114209a72c9c.tar.bz2 fork-ledger-7dd82f8bacf8dfb8db42a462452c114209a72c9c.zip |
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>
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ledger-mode.el | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index 79b6f0ec..b1df4a6b 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -168,16 +168,33 @@ Can indent, complete or align depending on context." nil 'noerr) (replace-match "")))))))) -(defun ledger-insert-effective-date () - (interactive) - (let ((context (car (ledger-context-at-point))) - (date-string (format-time-string (cdr (assoc "date-format" ledger-environment-alist))))) - (cond ((eq 'xact context) - (beginning-of-line) - (insert date-string "=")) - ((eq 'acct-transaction context) - (end-of-line) - (insert " ; [=" date-string "]"))))) +(defun ledger-insert-effective-date (&optional arg) + "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))) + (date-string (format-time-string + (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) + (re-search-forward ledger-iso-date-regexp) + (when (= (char-after) ?=) + (ledger-remove-effective-date)) + (insert "=" date-string)) + ((eq 'acct-transaction context) + (end-of-line) + (ledger-remove-effective-date) + (insert " ; [=" date-string "]"))))))) (defun ledger-mode-remove-extra-lines () (goto-char (point-min)) |