fix(beancount): completion edge cases

Like when `+beancount/clone-transaction` is invoked from an org-capture
template.
This commit is contained in:
Henrik Lissner
2025-05-30 20:54:27 +02:00
parent 4d685029f9
commit 96ac6b0037

View File

@ -39,11 +39,12 @@ will theirs, recursively)."
;;;###autoload ;;;###autoload
(defun +beancount--collect-unique-recursive (regexp n &optional context) (defun +beancount--collect-unique-recursive (regexp n &optional context)
(let ((results (make-hash-table :test 'equal))) (let ((results (make-hash-table :test 'equal))
(dolist (file (cons (buffer-file-name (buffer-base-buffer)) (buffer (or (buffer-base-buffer) (current-buffer)))
(if (eq +beancount-files 'auto) (files (if (eq +beancount-files 'auto)
(+beancount--included-files t context) (+beancount--included-files t context)
+beancount-files))) +beancount-files)))
(dolist (file (cons (buffer-file-name buffer) files))
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(dolist (x (beancount-collect-pos-alist regexp n)) (dolist (x (beancount-collect-pos-alist regexp n))
@ -60,9 +61,9 @@ will theirs, recursively)."
(category . ,(intern (format "beancount-%s" context))) (category . ,(intern (format "beancount-%s" context)))
(display-sort-function . identity)) (display-sort-function . identity))
(make-local-variable '+beancount--completion-cache) (make-local-variable '+beancount--completion-cache)
(with-current-buffer (let ((win (minibuffer-selected-window))) (with-current-buffer (if (active-minibuffer-window)
(if (window-live-p win) (window-buffer win) (window-buffer (minibuffer-selected-window))
(current-buffer))) (current-buffer))
(unless (assq context +beancount--completion-cache) (unless (assq context +beancount--completion-cache)
(with-memoization (alist-get context +beancount--completion-cache) (with-memoization (alist-get context +beancount--completion-cache)
(+beancount--collect-unique-recursive regexp n context))) (+beancount--collect-unique-recursive regexp n context)))