From 93c2daa33d3aac7c61f322c9d21f3ccab7bdcd4a Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 6 Mar 2022 10:14:42 -0500 Subject: [PATCH] (ecomplete-add-item): Preserve the more complete text Avoid replacing "John Doe " with "john@doe.ch". * lisp/ecomplete.el (ecomplete-add-item): Keep the longest text --- lisp/ecomplete.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el index c39c6c2ff9c..d5f3fc77560 100644 --- a/lisp/ecomplete.el +++ b/lisp/ecomplete.el @@ -103,7 +103,11 @@ string that was matched." (unless elems (push (setq elems (list type)) ecomplete-database)) (if (setq entry (assoc key (cdr elems))) - (setcdr entry (list (1+ (cadr entry)) now text)) + (pcase-let ((`(,_key ,count ,_time ,oldtext) entry)) + (setcdr entry (list (1+ count) now + ;; Preserve the "more complete" text. + (if (>= (length text) (length oldtext)) + text oldtext)))) (nconc elems (list (list key 1 now text)))))) (defun ecomplete-get-item (type key) -- 2.39.2