all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Philip Kaludercic <philipk@posteo.net>
Cc: 70010@debbugs.gnu.org
Subject: bug#70010: 30.0.50; completion-preview-mode behaves mode-local, but is global
Date: Tue, 26 Mar 2024 22:49:04 +0100	[thread overview]
Message-ID: <m1il18y88f.fsf@dazzs-mbp.kpn> (raw)
In-Reply-To: <875xx8g4e8.fsf@posteo.net> (Philip Kaludercic's message of "Tue,  26 Mar 2024 19:49:19 +0000")

[-- Attachment #1: Type: text/plain, Size: 2177 bytes --]

Philip Kaludercic <philipk@posteo.net> writes:

> Eshel Yaron <me@eshelyaron.com> writes:
>
>> Hello Philip,
>>
>> Philip Kaludercic <philipk@posteo.net> writes:
>>
>>> I tried to enable `completion-preview-mode' by adding
>>>
>>>   (setopt completion-preview-mode t)
>>>
>>> in my init, but it had not effect.
>>
>> Indeed, it is a minor mode, so one normally enables it by calling the
>> function completion-preview-mode, perhaps interactively via M-x.
>
> I enable all minor modes as user options, so I'd disagree that using a
> function or invoking the command are the only ways to expect a minor
> mode to be enabled.

Fair enough :)

>>> When I check the implementation, I noticed that it modifies
>>> `post-command-hook' locally.  I think it would make sense to rename
>>> the current `completion-preview-mode' to
>>> `completion-preview-local-mode', and then use
>>> `define-globalized-minor-mode' to define `completion-preview-mode'.
>>
>> We can add a global variant, although IMO the natural scope for
>> completion-preview-mode is per major mode: for some kinds of content you
>> want to have completion preview, and for others you may want it off.
>> Note that a necessary condition for completion-preview-mode to be useful
>> in a certain context is that completion-at-point is useful in that
>> context, since otherwise there's nothing to preview.
>>
>> Therefore, I recommend enabling completion-preview-mode by adding it to
>> major mode hooks, such as prog-mode-hook or comint-mode-hook.
>> Admittedly, if you do want to enable it for all buffers, the major mode
>> hook approach would require adding it to four or five hooks, which is a
>> bit less elegant than enabling a global minor mode once.
>>
>> So I suggest we keep completion-preview-mode local and add a global
>> variant, say, completion-preview-global-mode, for enabling it globally.
>> WDYT?
>
> That seems fine as well.

All right, here's a patch that adds such a global variant.  I find the
:predicate argument of define-globalized-minor-mode pretty neat, it adds
a user option that lets users choose in which major modes the minor mode
should take effect, and we can provide a sane default:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-global-minor-mode-completion-preview-global-mode.patch --]
[-- Type: text/x-patch, Size: 1037 bytes --]

From caca8078f95b8e2d6c67ada1da6fdb024262c5bc Mon Sep 17 00:00:00 2001
From: Eshel Yaron <me@eshelyaron.com>
Date: Tue, 26 Mar 2024 22:34:51 +0100
Subject: [PATCH] Add global minor mode 'completion-preview-global-mode'

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

* lisp/completion-preview.el (completion-preview-global-mode): New
global minor mode.  (Bug#70010)
---
 lisp/completion-preview.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el
index 75386f96429..f8a3c5ac4a2 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 completion-preview-global-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


  reply	other threads:[~2024-03-26 21:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 11:10 bug#70010: 30.0.50; completion-preview-mode behaves mode-local, but is global Philip Kaludercic
2024-03-26 19:10 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-26 19:49   ` Philip Kaludercic
2024-03-26 21:49     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-03-27  7:07       ` Juri Linkov
2024-03-27  9:24         ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-27 12:09       ` Eli Zaretskii
2024-03-27 16:05         ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-31  7:38           ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1il18y88f.fsf@dazzs-mbp.kpn \
    --to=bug-gnu-emacs@gnu.org \
    --cc=70010@debbugs.gnu.org \
    --cc=me@eshelyaron.com \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.