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