diff --git a/modules/lang/beancount/autoload.el b/modules/lang/beancount/autoload.el index 84e79716d..29d034bd2 100644 --- a/modules/lang/beancount/autoload.el +++ b/modules/lang/beancount/autoload.el @@ -125,3 +125,44 @@ If REVERSE (the prefix arg) is non-nil, sort the transactions in reverst order." (interactive) (let (compilation-read-command) (beancount--run "bean-report" buffer-file-name "bal"))) + +;;;###autoload +(defun +beancount/clone-transaction (transaction) + "TODO" + ;; TODO Ew. Refactor me! + (interactive + (save-restriction + (widen) + (list (completing-read + "Clone transaction: " + (nreverse + (cl-remove-if-not + (lambda (line) + (string-match-p "^[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [*!] \"" line)) + (split-string (substring-no-properties (buffer-string)) + "\n"))))))) + (when transaction + (goto-char (point-min)) + (re-search-forward (concat "^" (regexp-quote select))) + (+beancount/clone-this-transaction t))) + +;;;###autoload +(defun +beancount/clone-this-transaction (&optional arg) + "Copy the current transaction to the bottom of the ledger. +Updates the date to today" + (interactive "P") + (if (and (not arg) (looking-at-p "^$")) + (call-interactively #'+beancount/clone-transaction) + (let ((transaction + (buffer-substring-no-properties + (save-excursion + (beancount-goto-transaction-begin) + (re-search-forward " " nil t) + (point)) + (save-excursion + (beancount-goto-transaction-end) + (point))))) + (goto-char (point-max)) + (delete-blank-lines) + (beancount-insert-date) + (insert transaction)))) diff --git a/modules/lang/beancount/config.el b/modules/lang/beancount/config.el index a72474f5d..e52c098ca 100644 --- a/modules/lang/beancount/config.el +++ b/modules/lang/beancount/config.el @@ -28,6 +28,8 @@ "q" #'beancount-query "x" #'beancount-context (:prefix ("i" . "insert") + "c" #'+beancount/clone-transaction + "C" #'+beancount/clone-this-transaction "a" #'beancount-insert-account "p" #'beancount-insert-prices "d" #'beancount-insert-date)))