]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow filtering what items are added to Ecomplete
authorPhilip Kaludercic <philipk@posteo.net>
Thu, 13 Oct 2022 10:02:02 +0000 (12:02 +0200)
committerPhilip Kaludercic <philipk@posteo.net>
Fri, 14 Oct 2022 16:07:53 +0000 (18:07 +0200)
* etc/NEWS: Mention new option.
* lisp/ecomplete.el (ecomplete-filter-regexp): Add new option.
(ecomplete-add-item): Respect new option.  (bug#58487)

etc/NEWS
lisp/ecomplete.el

index 464cb2719f5cf791f6a6900723c23ea9076b3dcf..dcbf3a6aa32d5f950b28c8518e241e687f82a159 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1376,6 +1376,11 @@ the ecomplete database.
 *** New user option 'ecomplete-auto-select'.
 If non-nil and there's only one matching option, auto-select that.
 
+---
+*** New user option 'ecomplete-filter-regexp'.
+If non-nil this user option describes what email addresses to ignore
+and not add to the database.
+
 ** Dired
 
 +++
index 6ff67d46d20c7d3fb8da86f70d27dfdf3aa6465c..21f5f456ea00e5caa0c52520e0357134e085edbd 100644 (file)
@@ -86,6 +86,11 @@ string that was matched."
   :type 'boolean
   :version "29.1")
 
+(defcustom ecomplete-filter-regexp nil
+  "Regular expression of addresses to not store."
+  :type 'regexp
+  :version "29.1")
+
 ;;; Internal variables.
 
 (defvar ecomplete-database nil)
@@ -104,20 +109,22 @@ string that was matched."
 By default, the longest version of TEXT will be preserved, but if
 FORCE is non-nil, use TEXT exactly as is."
   (unless ecomplete-database (ecomplete-setup))
-  (let ((elems (assq type ecomplete-database))
-       (now (time-convert nil 'integer))
-       entry)
-    (unless elems
-      (push (setq elems (list type)) ecomplete-database))
-    (if (setq entry (assoc key (cdr elems)))
-       (pcase-let ((`(,_key ,count ,_time ,oldtext) entry))
-         (setcdr entry (list (1+ count) now
-                             ;; Preserve the "more complete" text.
-                             (if (or force
-                                      (>= (length text) (length oldtext)))
-                                 text
-                                oldtext))))
-      (nconc elems (list (list key 1 now text))))))
+  (unless (and ecomplete-filter-regexp
+               (string-match-p ecomplete-filter-regexp key))
+    (let ((elems (assq type ecomplete-database))
+          (now (time-convert nil 'integer))
+          entry)
+      (unless elems
+        (push (setq elems (list type)) ecomplete-database))
+      (if (setq entry (assoc key (cdr elems)))
+          (pcase-let ((`(,_key ,count ,_time ,oldtext) entry))
+            (setcdr entry (list (1+ count) now
+                                ;; Preserve the "more complete" text.
+                                (if (or force
+                                        (>= (length text) (length oldtext)))
+                                    text
+                                  oldtext))))
+        (nconc elems (list (list key 1 now text)))))))
 
 (defun ecomplete--remove-item (type key)
   "Remove the element of TYPE and KEY from the ecomplete database."