Subject: Re: bug#11046: 24.0.94; Customize: M-TAB moves cursor over tag; clicking button moves cursor over button

From: Mauro Aranda <[email-masked]>
Date: Sat, 5 Oct 2019 10:15:10 -0300

Lars Ingebrigtsen <[email-masked]> writes:

> Mauro Aranda <[email-masked]> writes:
>
> I think that makes sense...
>
>> -  :complete-function 'ispell-complete-word
>> +  :complete (lambda (widget)
>> +              (eval-and-compile (require 'ispell)) ; For
`ispell-get-word'.
>
> I think the way we usually do this is by just saying (require 'ispell)
> in the function, and pacify the compiler by using a `declare-function'.

Thanks for reviewing.  I attach a patch with that change.

Best regards,
Mauro.
From 4893dc6633fff6756ba3c8af63279448f1925786 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Wed, 25 Sep 2019 19:40:35 -0300
Subject: [PATCH] Only complete words inside of the string widget

* lisp/wid-edit.el ('string widget): Peek the word that
ispell-complete-word will try to complete, and only offer completions
when the word is inside of the field.  (Bug#11046)
---
 lisp/wid-edit.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 916d41a..28d8dfc 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -58,6 +58,10 @@
 (require 'cl-lib)
 (eval-when-compile (require 'subr-x)) 	; when-let
 
+;; The `string' widget completion uses this.
+(declare-function ispell-get-word "ispell"
+                  (following &optional extra-otherchars))
+
 ;;; Compatibility.
 
 (defun widget-event-point (event)
@@ -3073,7 +3077,12 @@ 'string
   "A string."
   :tag "String"
   :format "%{%t%}: %v"
-  :complete-function 'ispell-complete-word
+  :complete (lambda (widget)
+              (require 'ispell)
+              (let ((start (save-excursion (nth 1 (ispell-get-word nil)))))
+                (if (< start (widget-field-start widget))
+                    (message "No word to complete inside field")
+                  (ispell-complete-word))))
   :prompt-history 'widget-string-prompt-value-history)
 
 (define-widget 'regexp 'string
-- 
2.7.4