Subject: bug#70010: 30.0.50; completion-preview-mode behaves mode-local, but is global

From: Eshel Yaron <[email-masked]>
Date: Wed, 27 Mar 2024 17:05:29 +0100

Eli Zaretskii <[email-masked]> writes:

> Thanks, but please add a NEWS entry announcing this, and also mention
> this variant in the user manual, where completion-preview-mode is
> documented.

All right, I'm attaching an updated patch below.  Since
'completion-preview-mode' is new in Emacs 30, I extended the existing
NEWS entry with a mention of the global variant, instead of adding
another entry.  I've also renamed the global variant per Juri's comment:

>From 828544ab372d5e7731772b9854732c9373497903 Mon Sep 17 00:00:00 2001
From: Eshel Yaron <[email-masked]>
Date: Tue, 26 Mar 2024 22:34:51 +0100
Subject: [PATCH v2] Add global minor mode 'global-completion-preview-mode'

This is a global variant of 'completion-preview-mode'.

* lisp/completion-preview.el (global-completion-preview-mode): New
global minor mode.

* doc/emacs/programs.texi (Symbol Completion): Document it.

* etc/NEWS: Announce it.  (Bug#70010)
---
 doc/emacs/programs.texi    | 11 +++++++----
 etc/NEWS                   |  2 ++
 lisp/completion-preview.el |  4 ++++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi
index 1627e7e6cb7..de28a9f1dd4 100644
--- a/doc/emacs/programs.texi
+++ b/doc/emacs/programs.texi
@@ -1706,11 +1706,14 @@ Symbol Completion
 @cindex suggestion preview
 @cindex Completion Preview mode
 @findex completion-preview-mode
+@findex global-completion-preview-mode
   Completion Preview mode is a minor mode that shows completion
-suggestions as you type.  When you enable this mode (with @kbd{M-x
-completion-preview-mode}), Emacs automatically displays the
-suggested completion for text around point as an in-line preview
-right after point; type @key{TAB} to accept the suggestion.
+suggestions as you type.  You can enable it for the current buffer with
+@kbd{M-x completion-preview-mode}, or globally with @w{@kbd{M-x
+global-completion-preview-mode}}.  When Completion Preview mode is on,
+Emacs automatically displays the suggested completion for text around
+point as an in-line preview right after point; type @key{TAB} to accept
+the suggestion.
 
 @node MixedCase Words
 @section MixedCase Words
diff --git a/etc/NEWS b/etc/NEWS
index 60fe75fc340..906bf5a9c3c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1644,6 +1644,8 @@ sexp navigation more intuitive.
 This minor mode shows you symbol completion suggestions as you type,
 using an inline preview.  New user options in the 'completion-preview'
 customization group control exactly when Emacs displays this preview.
+'completion-preview-mode' is buffer-local, to enable it globally use
+'global-completion-preview-mode'.
 
 +++
 *** New user option 'extended-command-dim-hyphens'.
diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el
index 75386f96429..c9f3a81b879 100644
--- a/lisp/completion-preview.el
+++ b/lisp/completion-preview.el
@@ -414,5 +414,9 @@ completion-preview-mode
     (remove-hook 'post-command-hook #'completion-preview--post-command t)
     (completion-preview-active-mode -1)))
 
+(define-globalized-minor-mode global-completion-preview-mode
+  completion-preview-mode completion-preview-mode
+  :predicate '((not minibuffer-mode special-mode) t))
+
 (provide 'completion-preview)
 ;;; completion-preview.el ends here
-- 
2.44.0