From 96ac6b0037226758ed6742fd3a1f5add6d72f1ac Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 30 May 2025 20:54:27 +0200 Subject: [PATCH] fix(beancount): completion edge cases Like when `+beancount/clone-transaction` is invoked from an org-capture template. --- modules/lang/beancount/autoload/advice.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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)))