diff --git a/modules/lang/beancount/autoload.el b/modules/lang/beancount/autoload.el index e23acb4d4..09a513d4d 100644 --- a/modules/lang/beancount/autoload.el +++ b/modules/lang/beancount/autoload.el @@ -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"))) ;;;###autoload -(defun +beancount/clone-transaction (transaction) +(defun +beancount/clone-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 transaction))) - (+beancount/clone-this-transaction t))) + (interactive) + (save-restriction + (widen) + (when-let (transaction + (completing-read + "Clone transaction: " + (string-lines (buffer-string)) + (doom-partial #'string-match-p "^[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [*!] ") + t)) + (goto-char (point-min)) + (re-search-forward (concat "^" (regexp-quote transaction))) + (+beancount/clone-this-transaction t)))) ;;;###autoload (defun +beancount/clone-this-transaction (&optional arg) @@ -153,16 +149,18 @@ 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)))) + (save-restriction + (widen) + (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)))))