From 47b48346a3e6d5e198079bf29afcbc9c7201dcd3 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 13 Feb 2026 11:54:47 +0100 Subject: [PATCH 1/2] 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 From 048e9553a8cc966616c01337af07a1f31a3972f1 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 14 Feb 2026 12:26:53 +0100 Subject: [PATCH 2/2] ; Add t as a possible value for 'completion-preview-commands' * lisp/completion-preview.el (completion-preview-commands): Allow the value t, which says that completion preview should be attempted after any command. * lisp/completion-preview.el (completion-preview-require-certain-commands): Adapt. --- lisp/completion-preview.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index bf0ba949d61..5a1a6b5ed43 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -159,8 +159,12 @@ first candidate, and you can cycle between the candidates with completion-preview-complete completion-preview-insert-word completion-preview-insert-sexp) - "List of commands that should trigger completion preview." - :type '(repeat (function :tag "Command" :value self-insert-command)) + "List of commands that should trigger completion preview. +This can also be t instead of a list of commands, which says that any +command can trigger completion preview." + :type '(choice (repeat :tag "Specific commands" + (function :tag "Command" :value self-insert-command)) + (const :tag "Any command" t)) :version "30.1") (defcustom completion-preview-minimum-symbol-length 3 @@ -334,7 +338,8 @@ Completion Preview mode avoids updating the preview after these commands.") (defsubst completion-preview-require-certain-commands () "Check if `this-command' is one of `completion-preview-commands'." - (memq this-command completion-preview-commands)) + (or (eq completion-preview-commands t) + (memq this-command completion-preview-commands))) (defun completion-preview-require-minimum-symbol-length () "Check if the length of symbol at point is at least above a certain threshold.