From 47b48346a3e6d5e198079bf29afcbc9c7201dcd3 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 13 Feb 2026 11:54:47 +0100 Subject: [PATCH] New option 'completion-preview-inhibit-functions' (bug#80370) * lisp/completion-preview.el (completion-preview-inhibit-functions): New option. (completion-preview--post-command): Respect it. * etc/NEWS: Announce it. --- etc/NEWS | 6 ++++++ lisp/completion-preview.el | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index d1585c8309d..368151d2201 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -295,6 +295,12 @@ that your popup interface uses for a more integrated experience. ('completion-preview-sort-function' was already present in Emacs 30.1, but as a plain Lisp variable, not a user option.) +--- +*** New user option 'completion-preview-inhibit-functions'. +This option provides fine-grained control over Completion Preview mode +activation. You can use it to specify arbitrary conditions in which to +inhibit the mode's operation. + --- *** New mode 'minibuffer-nonselected-mode'. This mode, enabled by default, directs the attention to the active diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index c58f615de81..bf0ba949d61 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -98,6 +98,14 @@ ;; when you pause typing for a short duration rather than after every ;; key. Try setting it to 0.2 seconds and see how that works for you. ;; +;; The user option `completion-preview-inhibit-functions' lets you +;; specify additional arbitrary conditions for inhibiting the preview. +;; For example, if you'd like to inhibit Completion Preview mode during +;; keyboard macro execution, you could use something like this: +;; +;; (add-hook 'completion-preview-inhibit-functions +;; (lambda () executing-kbd-macro)) +;; ;; By default, Completion Preview mode automatically adapts the ;; background color of the preview overlay to match the background color ;; of the buffer text it's completing. If you prefer a distinct @@ -606,6 +614,13 @@ point, otherwise hide it." (selected-window) (current-buffer))) (completion-preview--try-update))) +(defcustom completion-preview-inhibit-functions nil + "Abnormal hook for inhibiting Completion Preview mode operation. +Completion Preview mode calls the functions on this hook without +arguments during `post-command-hook'. If any of these functions returns +non-nil, it inhibits the preview display." + :type 'hook) + (defun completion-preview--post-command () "Create, update or delete completion preview post last command." (let ((internal-p (or completion-preview--inhibit-update-p @@ -623,7 +638,8 @@ point, otherwise hide it." ) ((and (completion-preview-require-certain-commands) (completion-preview-require-minimum-symbol-length) - (not buffer-read-only)) + (not buffer-read-only) + (not (run-hook-with-args-until-success 'completion-preview-inhibit-functions))) ;; All conditions met. Show or update the preview. (completion-preview--show)) (completion-preview-active-mode