Subject: Re: bug#67527: 30.0.50; FR: Add an option to disable ispell completion in text-mode

From: Eshel Yaron <[email-masked]>
Date: Sat, 20 Jan 2024 12:33:25 +0100

Hi,

Eli Zaretskii <[email-masked]> writes:

>> From: Daniel Mendler <[email-masked]>
>>
>> Eli Zaretskii <[email-masked]> writes:
>>
>> >> From: Daniel Mendler <[email-masked]>
>> >>
>> >> Eli Zaretskii <[email-masked]> writes:
>> >>
>> >> > Eshel, given this feedback, I think it would make sense to add a new
>> >> > defcustom that would make text-mode avoid adding
>> >> > ispell-completion-at-point to completion-at-point-functions.  Would
>> >> > you please submit such a change and the documentation changes to go
>> >> > with it?  TIA.
>> >>
>> >> Maybe the existing defcustom `text-mode-meta-tab-ispell-complete-word'
>> >> could be renamed and reused, taking three values? This way we avoid
>> >> introducing multiple defcustoms for tweaking the same feature.
>> >>
>> >> - `command': Bind `ispell-complete-word' to TAB.
>> >> - `capf': Add `ispell-completion-at-point' to the
>> >>   `completion-at-point-functions'.
>> >> - `nil': None of the above.
>> >
>> > Reused, yes.  Renamed, I'd rather prefer we avoided that, as it causes
>> > compatibility problems.  If we can extend its list of valid values to
>> > support this aspect as well, it would be good.
>>
>> Iiuc the variable was introduced a short while ago on Emacs master, so
>> renaming it may still be possible?
>
> Oh, I think I confused it with another option.  Yes, if it was
> introduced recently on master, we can rename it.

SGTM, see attached patch below.

>From 8ed03422c140be6a7f6f5352c2906b52a7c22a1d Mon Sep 17 00:00:00 2001
From: Eshel Yaron <[email-masked]>
Date: Sat, 20 Jan 2024 12:24:32 +0100
Subject: [PATCH] Optionally avoid extending 'c-a-p-f' in Text mode (Bug#67527)

* lisp/textmodes/text-mode.el
(text-mode-meta-tab-ispell-complete-word): Rename to...
(text-mode-ispell-word-completion): ...this.  Extend with another
option 'completion-at-point'.
(text-mode): Only extend 'completion-at-point-functions' when
'text-mode-ispell-word-completion' is 'completion-at-point'.

* etc/NEWS: Update.
---
 etc/NEWS                    | 13 +++++++------
 lisp/textmodes/text-mode.el | 19 ++++++++++++++-----
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 013d76eb44b..c1b34d2765e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1404,12 +1404,13 @@ files and save the changes.
 
 +++
 ** 'M-TAB' now invokes 'completion-at-point' also in Text mode.
-Text mode no longer binds 'M-TAB' to 'ispell-complete-word', and
-instead this mode arranges for 'completion-at-point', globally bound
-to 'M-TAB', to perform word completion as well.  If you want 'M-TAB'
-to invoke 'ispell-complete-word', as it did in previous Emacs
-versions, customize the new user option
-'text-mode-meta-tab-ispell-complete-word' to non-nil.
+By default, Text mode no longer binds 'M-TAB' to
+'ispell-complete-word'.  Instead this mode arranges for
+'completion-at-point', globally bound to 'M-TAB', to perform word
+completion as well.  You can have Text mode bind 'M-TAB' to
+'ispell-complete-word' as it did in previous Emacs versions, or
+disable Ispell word completion in Text mode altogether, by customizing
+the new user option 'text-mode-ispell-word-completion'.
 
 ** 'pp' and 'pp-to-string' now always include a terminating newline.
 In the past they included a terminating newline in most cases but not all.
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 7d3b47a9c03..87f6668cecb 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -75,8 +75,15 @@ text-mode-map
 Many other modes, such as `mail-mode' and `outline-mode', inherit
 all the commands defined in this map.")
 
-(defcustom text-mode-meta-tab-ispell-complete-word nil
-  "Whether M-TAB invokes `ispell-complete-word' in Text mode.
+(defcustom text-mode-ispell-word-completion 'completion-at-point
+  "How Text mode provides Ispell word completion.
+
+By default, this option is set to `completion-at-point', which
+means that Text mode adds an Ispell word completion function to
+`completion-at-point-functions'.  Any other non-nil value says to
+bind M-TAB directly to `ispell-complete-word' instead.  If this
+is nil, Text mode neither binds M-TAB to `ispell-complete-word'
+nor does it extend `completion-at-point-functions'.
 
 This user option only takes effect when you customize it in
 Custom or with `setopt', not with `setq'."
@@ -84,8 +91,9 @@ text-mode-meta-tab-ispell-complete-word
   :type 'boolean
   :version "30.1"
   :set (lambda (sym val)
-         (if (set sym val)
-	     (keymap-set text-mode-map "C-M-i" #'ispell-complete-word)
+         (if (and (set sym val)
+                  (not (eq val 'completion-at-point)))
+             (keymap-set text-mode-map "C-M-i" #'ispell-complete-word)
            (keymap-unset text-mode-map "C-M-i" t))))
 
 (easy-menu-define text-mode-menu text-mode-map
@@ -144,7 +152,8 @@ text-mode
   ;; Enable text conversion in this buffer.
   (setq-local text-conversion-style t)
   (add-hook 'context-menu-functions 'text-mode-context-menu 10 t)
-  (add-hook 'completion-at-point-functions #'ispell-completion-at-point 10 t))
+  (when (eq text-mode-ispell-word-completion 'completion-at-point)
+    (add-hook 'completion-at-point-functions #'ispell-completion-at-point 10 t)))
 
 (define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
   "Major mode for editing text, with leading spaces starting a paragraph.
-- 
2.42.0