refactor(beancount): +beancount/clone-transaction
This commit is contained in:
parent
c309e61eff
commit
86a8b41e37
1 changed files with 28 additions and 30 deletions
|
@ -127,24 +127,20 @@ If REVERSE (the prefix arg) is non-nil, sort the transactions in reverst order."
|
||||||
(beancount--run "bean-report" buffer-file-name "bal")))
|
(beancount--run "bean-report" buffer-file-name "bal")))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +beancount/clone-transaction (transaction)
|
(defun +beancount/clone-transaction ()
|
||||||
"TODO"
|
"TODO"
|
||||||
;; TODO Ew. Refactor me!
|
(interactive)
|
||||||
(interactive
|
(save-restriction
|
||||||
(save-restriction
|
(widen)
|
||||||
(widen)
|
(when-let (transaction
|
||||||
(list (completing-read
|
(completing-read
|
||||||
"Clone transaction: "
|
"Clone transaction: "
|
||||||
(nreverse
|
(string-lines (buffer-string))
|
||||||
(cl-remove-if-not
|
(doom-partial #'string-match-p "^[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [*!] ")
|
||||||
(lambda (line)
|
t))
|
||||||
(string-match-p "^[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [*!] \"" line))
|
(goto-char (point-min))
|
||||||
(split-string (substring-no-properties (buffer-string))
|
(re-search-forward (concat "^" (regexp-quote transaction)))
|
||||||
"\n")))))))
|
(+beancount/clone-this-transaction t))))
|
||||||
(when transaction
|
|
||||||
(goto-char (point-min))
|
|
||||||
(re-search-forward (concat "^" (regexp-quote transaction)))
|
|
||||||
(+beancount/clone-this-transaction t)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +beancount/clone-this-transaction (&optional arg)
|
(defun +beancount/clone-this-transaction (&optional arg)
|
||||||
|
@ -153,16 +149,18 @@ Updates the date to today"
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(if (and (not arg) (looking-at-p "^$"))
|
(if (and (not arg) (looking-at-p "^$"))
|
||||||
(call-interactively #'+beancount/clone-transaction)
|
(call-interactively #'+beancount/clone-transaction)
|
||||||
(let ((transaction
|
(save-restriction
|
||||||
(buffer-substring-no-properties
|
(widen)
|
||||||
(save-excursion
|
(let ((transaction
|
||||||
(beancount-goto-transaction-begin)
|
(buffer-substring-no-properties
|
||||||
(re-search-forward " " nil t)
|
(save-excursion
|
||||||
(point))
|
(beancount-goto-transaction-begin)
|
||||||
(save-excursion
|
(re-search-forward " " nil t)
|
||||||
(beancount-goto-transaction-end)
|
(point))
|
||||||
(point)))))
|
(save-excursion
|
||||||
(goto-char (point-max))
|
(beancount-goto-transaction-end)
|
||||||
(delete-blank-lines)
|
(point)))))
|
||||||
(beancount-insert-date)
|
(goto-char (point-max))
|
||||||
(insert transaction))))
|
(delete-blank-lines)
|
||||||
|
(beancount-insert-date)
|
||||||
|
(insert transaction)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue