[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [elpa] externals/ebdb 9e7a96f: Add experimental ebdb-completion-at-p

From: Stefan Monnier
Subject: Re: [elpa] externals/ebdb 9e7a96f: Add experimental ebdb-completion-at-point-function
Date: Fri, 23 Mar 2018 08:23:07 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> Looks like you added that FIXME! If you outline how you think this ought
> to look, I can take a stab at patching message.el. At what level should
> these functions be intervening?

One of the main issue is preserving backward compatibility with existing
functions the user may have set in message-completion-alist.

I have already some local patches to try and do some of that, so see
patch below (I hand-edited it to remove irrelevant other cosmetic
changes, so don't try to pass it to `patch`).

> My only reservation is that BBDB/EBDB mail completion first completes a
> contact mail address, and subsequently cycles through that contact's
> other addresses. Is this something that the standard mechanisms can
> replicate?

You can get cycling via completion-cycle-threshold, yes.


diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index e452c80e26..c99708845d 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -7930,6 +7936,8 @@ message-tab
 (defvar mail-abbrev-mode-regexp)
+(defvar message--old-style-completion-functions nil)
 (defun message-completion-function ()
   (let ((alist message-completion-alist))
     (while (and alist
@@ -7938,9 +7946,21 @@ message-completion-function
       (setq alist (cdr alist)))
     (when (cdar alist)
       (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)))))
+        (if (member fun message--old-style-completion-functions)
+            ;; 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)
+          (let ((ticks-before (buffer-chars-modified-tick))
+                (data (funcall fun)))
+            (if (and (eq ticks-before (buffer-chars-modified-tick))
+                     (or (null data)
+                         (integerp (car-safe data))))
+                data
+              (push fun message--old-style-completion-functions)
+              ;; Completion was already performed, so just return a dummy
+              ;; function that prevents trying any further.
+              (lambda () 'completion-attempted))))))))
 (defun message-expand-group ()
   "Expand the group name under point."
@@ -7966,7 +8083,9 @@ message-expand-group
-    (completion-in-region b e collection)))
+    ;; FIXME: Add `category' metadata to the collection, so we can use
+    ;; substring matching on it.
+    (list b e collection)))
 (defun message-expand-name ()
   (cond ((and (memq 'eudc message-expand-name-databases)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]