Skip to content

Commit 47e313e

Browse files
eshelyaronEli-Zaretskii
authored andcommitted
Unbind 'C-M-i' in Text mode
Remove the binding of 'C-M-i' to 'ispell-complete-word' in Text mode. Define a new 'ispell-completion-at-point' function and add that to 'completion-at-point-functions' in Text mode, such that 'completion-at-point' provides the same word completions as 'ispell-complete-word' does OOTB. * lisp/textmodes/ispell.el (ispell-completion-at-point): New function. * lisp/textmodes/text-mode.el (text-mode): Add it to 'c-a-p-functions'. (text-mode-map): Remove 'C-M-i' binding. (text-mode-meta-tab-ispell-complete-word): New user option. * etc/NEWS: Announce it. * doc/emacs/fixit.texi (Spelling) * doc/emacs/text.texi (Text Mode) * doc/lispref/modes.texi (Basic Major Modes) (Example Major Modes): Update. * lisp/mail/sendmail.el (mail-abbrevs-loaded) * lisp/nxml/nxml-mode.el (nxml-mode-map): Remove superfluous binding.
1 parent 7304cc8 commit 47e313e

File tree

8 files changed

+62
-32
lines changed

8 files changed

+62
-32
lines changed

doc/emacs/fixit.texi

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ Kill the spell-checker subprocess.
295295
@item M-@key{TAB}
296296
@itemx @key{ESC} @key{TAB}
297297
@itemx C-M-i
298-
Complete the word before point based on the spelling dictionary
299-
(@code{ispell-complete-word}).
298+
Complete the word before point based on the spelling dictionary and
299+
other completion sources (@code{completion-at-point}).
300300
@item M-x flyspell-mode
301301
Enable Flyspell mode, which highlights all misspelled words.
302302
@item M-x flyspell-prog-mode
@@ -398,14 +398,11 @@ Quit interactive spell-checking and kill the spell-checker subprocess.
398398
Show the list of options.
399399
@end table
400400

401-
@findex ispell-complete-word
402-
In Text mode and related modes, @kbd{M-@key{TAB}}
403-
(@code{ispell-complete-word}) performs in-buffer completion based on
404-
spelling correction. Insert the beginning of a word, and then type
405-
@kbd{M-@key{TAB}}; this shows a list of completions. (If your
401+
Use the command @kbd{M-@key{TAB}} (@code{completion-at-point}) to
402+
complete the word at point. Insert the beginning of a word, and then
403+
type @kbd{M-@key{TAB}} to select from a list of completions. (If your
406404
window manager intercepts @kbd{M-@key{TAB}}, type @w{@kbd{@key{ESC}
407-
@key{TAB}}} or @kbd{C-M-i}.) Each completion is listed with a digit or
408-
character; type that digit or character to choose it.
405+
@key{TAB}}} or @kbd{C-M-i}.)
409406

410407
@cindex @code{ispell} program
411408
@findex ispell-kill-ispell

doc/emacs/text.texi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,12 @@ situations where you shouldn't change the major mode---in mail
943943
composition, for instance.
944944

945945
@kindex M-TAB @r{(Text mode)}
946-
Text mode binds @kbd{M-@key{TAB}} to @code{ispell-complete-word}.
947-
This command performs completion of the partial word in the buffer
948-
before point, using the spelling dictionary as the space of possible
949-
words. @xref{Spelling}. If your window manager defines
950-
@kbd{M-@key{TAB}} to switch windows, you can type @kbd{@key{ESC}
951-
@key{TAB}} or @kbd{C-M-i} instead.
946+
The command @kbd{M-@key{TAB}} (@code{completion-at-point}) performs
947+
completion of the partial word in the buffer before point, using the
948+
spelling dictionary as the space of possible words by default.
949+
@xref{Spelling}. If your window manager defines @kbd{M-@key{TAB}} to
950+
switch windows, you can type @kbd{@key{ESC} @key{TAB}} or @kbd{C-M-i}
951+
instead.
952952

953953
@vindex text-mode-hook
954954
Entering Text mode runs the mode hook @code{text-mode-hook}

doc/lispref/modes.texi

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,9 @@ allows users to customize a single mode hook
986986
@deffn Command text-mode
987987
Text mode is a major mode for editing human languages. It defines the
988988
@samp{"} and @samp{\} characters as having punctuation syntax
989-
(@pxref{Syntax Class Table}), and binds @kbd{M-@key{TAB}} to
990-
@code{ispell-complete-word} (@pxref{Spelling,,, emacs, The GNU Emacs
991-
Manual}).
989+
(@pxref{Syntax Class Table}), and arranges for
990+
@code{completion-at-point} to complete words based on the spelling
991+
dictionary (@pxref{Completion in Buffers}).
992992

993993
An example of a major mode derived from Text mode is HTML mode.
994994
@xref{HTML Mode,,SGML and HTML Modes, emacs, The GNU Emacs Manual}.
@@ -1382,15 +1382,6 @@ the conventions listed above:
13821382
st)
13831383
"Syntax table used while in `text-mode'.")
13841384
@end group
1385-
1386-
;; @r{Create the keymap for this mode.}
1387-
@group
1388-
(defvar-keymap text-mode-map
1389-
:doc "Keymap for `text-mode'.
1390-
Many other modes, such as `mail-mode' and `outline-mode', inherit all
1391-
the commands defined in this map."
1392-
"C-M-i" #'ispell-complete-word)
1393-
@end group
13941385
@end smallexample
13951386

13961387
Here is how the actual mode command is defined now:

etc/NEWS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,15 @@ showcases all their customization options.
11321132

11331133
* Incompatible Lisp Changes in Emacs 30.1
11341134

1135+
+++
1136+
** 'M-TAB' now invokes 'completion-at-point' also in Text mode.
1137+
Text mode no longer binds 'M-TAB' to 'ispell-complete-word', and
1138+
instead this mode arranges for 'completion-at-point', globally bound
1139+
to 'M-TAB', to perform word completion as well. If you want 'M-TAB'
1140+
to invoke 'ispell-complete-word', as it did in previous Emacs
1141+
versions, customize the new option
1142+
'text-mode-meta-tab-ispell-complete-word' to non-nil.
1143+
11351144
** 'pp' and 'pp-to-string' now always include a terminating newline.
11361145
In the past they included a terminating newline in most cases but not all.
11371146

lisp/mail/sendmail.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ The default value matches citations like `foo-bar>' plus whitespace."
269269
(defvar mail-abbrevs-loaded nil)
270270
(defvar mail-mode-map
271271
(let ((map (make-sparse-keymap)))
272-
(define-key map "\M-\t" 'completion-at-point)
273272
(define-key map "\C-c?" 'describe-mode)
274273
(define-key map "\C-c\C-f\C-t" 'mail-to)
275274
(define-key map "\C-c\C-f\C-b" 'mail-bcc)

lisp/nxml/nxml-mode.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ reference.")
390390
"C-c C-u" #'nxml-insert-named-char
391391
"C-c C-o" nxml-outline-prefix-map
392392
"/" #'nxml-electric-slash
393-
"M-TAB" #'completion-at-point
394393
"S-<mouse-2>" #'nxml-mouse-hide-direct-text-content)
395394

396395
(defvar nxml-font-lock-keywords

lisp/textmodes/ispell.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,6 +3680,28 @@ If APPEND is non-nil, don't erase previous debugging output."
36803680
(if (>= column (- (window-width) 2))
36813681
(scroll-left (max (- column (window-width) -3) 10)))))))
36823682

3683+
;;;###autoload
3684+
(defun ispell-completion-at-point ()
3685+
"Word completion function for use in `completion-at-point-functions'."
3686+
(pcase (bounds-of-thing-at-point 'word)
3687+
(`(,beg . ,end)
3688+
(when (and (< beg (point)) (<= (point) end))
3689+
(let* ((word (buffer-substring-no-properties beg end))
3690+
(len (length word))
3691+
(inhibit-message t)
3692+
(all (cons word (ispell-lookup-words word)))
3693+
(cur all))
3694+
(while cur
3695+
(unless (string-prefix-p word (car cur))
3696+
(setcar cur (concat word (substring (car cur) len))))
3697+
(while (when-let ((next (cadr cur)))
3698+
(not (string-prefix-p word next t)))
3699+
(setcdr cur (cddr cur)))
3700+
(setq cur (cdr cur)))
3701+
(list beg end (cdr all)
3702+
:annotation-function (lambda (_) " Dictionary word")
3703+
:exclusive 'no))))))
3704+
36833705

36843706
;;; Interactive word completion.
36853707
;; Forces "previous-word" processing. Do we want to make this selectable?

lisp/textmodes/text-mode.el

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,20 @@
7373
(defvar-keymap text-mode-map
7474
:doc "Keymap for `text-mode'.
7575
Many other modes, such as `mail-mode' and `outline-mode', inherit
76-
all the commands defined in this map."
77-
"C-M-i" #'ispell-complete-word)
76+
all the commands defined in this map.")
77+
78+
(defcustom text-mode-meta-tab-ispell-complete-word nil
79+
"Whether M-TAB invokes `ispell-complete-word' in Text mode.
80+
81+
This user option only takes effect when you customize it in
82+
Custom or with `setopt', not with `setq'."
83+
:group 'text
84+
:type 'boolean
85+
:version "30.1"
86+
:set (lambda (sym val)
87+
(if (set sym val)
88+
(keymap-set text-mode-map "C-M-i" #'ispell-complete-word)
89+
(keymap-unset text-mode-map "C-M-i" t))))
7890

7991
(easy-menu-define text-mode-menu text-mode-map
8092
"Menu for `text-mode'."
@@ -131,7 +143,8 @@ Turning on Text mode runs the normal hook `text-mode-hook'."
131143

132144
;; Enable text conversion in this buffer.
133145
(setq-local text-conversion-style t)
134-
(add-hook 'context-menu-functions 'text-mode-context-menu 10 t))
146+
(add-hook 'context-menu-functions 'text-mode-context-menu 10 t)
147+
(add-hook 'completion-at-point-functions #'ispell-completion-at-point 10 t))
135148

136149
(define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
137150
"Major mode for editing text, with leading spaces starting a paragraph.

0 commit comments

Comments
 (0)