Subject: bug#9158: 24.0.50; Regression in e-mail heade completion

From: Stefan Monnier <[email-masked]>
Date: Fri, 21 Oct 2011 18:57:04 -0400

>>> I get the message "completion for "foo" unfound" which is fine. The bug
>>> is that the cursor moves forward several spaces.  Apparently
>>> indent-relative gets called when it shouldn't.
>>> I expected the cursor to remain at the end of the entry that did not
>>> match.  It worked fine on 23.3.
>> The way the new code works can't handle this correctly because the BBDB
>> code doesn't indicate that something happened: it just always returns nil
>> whether something was done or not.
>> The new BBDB-3 has fixed this, AFAIK, so you may want to try that out.
> I have just installed bbdb 3.  It doesn't fix it.  I'll reopen the bug
> because it's a regression.

After looking into it some more, I realized that it's actually behaving
as designed, but not as documented in the docstring.

Could you try the patch below?

        Stefan

=== modified file 'lisp/gnus/message.el'
--- lisp/gnus/message.el	2011-10-11 13:02:03 +0000
+++ lisp/gnus/message.el	2011-10-21 22:54:20 +0000
@@ -7892,7 +7892,11 @@
 		(let ((mail-abbrev-mode-regexp (caar alist)))
 		  (not (mail-abbrev-in-expansion-header-p))))
       (setq alist (cdr alist)))
-    (cdar alist)))
+    (when (cdar alist)
+      (lexical-let ((fun (cdar alist)))
+        ;; Even if completion fails, return a non-nil value, so as to avoid
+        ;; falling back to message-tab-body-function.
+        (lambda () (funcall fun) 'completion-attempted)))))
 
 (defun message-debbugs-completion ()
   (save-excursion