From: Stefan Monnier Date: Sun, 6 Mar 2022 15:14:42 +0000 (-0500) Subject: (ecomplete-add-item): Preserve the more complete text X-Git-Tag: emacs-29.0.90~1991 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=93c2daa33d3aac7c61f322c9d21f3ccab7bdcd4a;p=emacs.git (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 --- 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)