feat(beancount): add clone-transaction commands

This commit is contained in:
Henrik Lissner 2022-02-09 14:54:49 +01:00
parent 009613a470
commit 958472b048
2 changed files with 43 additions and 0 deletions

View file

@ -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))))

View file

@ -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)))