From a24ff52a79b4ef91fa36cba1406e4112b24fa167 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 30 Apr 2026 21:19:19 +0200 Subject: [PATCH] New variable 'completion-preview-is-calling' * lisp/completion-preview.el (completion-preview-is-calling): New variable. (completion-preview--capf-wrapper): Bind it to t when calling the CAPF. * etc/NEWS: Announce it. --- etc/NEWS | 5 +++++ lisp/completion-preview.el | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index c54941382c3..8f266f2d670 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -4489,6 +4489,11 @@ the minibuffer, instead of waiting with 'sit-for' and then clearing it. This makes 'minibuffer-message' usable in Lisp programs which want to print a message and then continue to perform work. +--- +** New variable 'completion-preview-is-calling'. +Completion functions (in 'completion-at-point-functions') can check this +variable to tell if they are being called by Completion Preview mode. + ** Special Events +++ diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index ff348ebf9af..907068fdb67 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -523,9 +523,20 @@ candidates or if there are multiple matching completions and (setq sorted (cdr sorted))) (list (substring string 0 base) common suffixes)))))) +(defvar completion-preview-is-calling nil + "Non-nil while Completion Preview mode is calling a completion function. + +Completion functions (in `completion-at-point-functions') can check this +variable and adjust their behavior for completion preview. +For example, a completion function can skip calculating annotations for +candidates it produces for display in the completion preview, which does +not make use of such annotations.") + (defun completion-preview--capf-wrapper (capf) "Translate return value of CAPF to properties for completion preview overlay." - (let ((res (ignore-errors (funcall capf)))) + (let ((res (ignore-errors + (let ((completion-preview-is-calling t)) + (funcall capf))))) (and (consp res) (not (functionp res)) (seq-let (beg end table &rest plist) res