unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#58487: [PATCH] Allow filtering what items are added to Ecomplete
@ 2022-10-13 10:06 Philip Kaludercic
  2022-10-13 18:00 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Philip Kaludercic @ 2022-10-13 10:06 UTC (permalink / raw)
  To: 58487

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

Tags: patch


I've had this as a customisation in my local .emacs file, implemented as
advice around ecomplete-add-item:

--8<---------------cut here---------------start------------->8---
(define-advice ecomplete-add-item (:around (oldfun type key text))
  "Filter out common pseudo addresses from the database.
OLDFUN is `ecomplete-add-item', passed by `advice-add', that will
be invoked with TYPE, KEY and TEXT if KEY doesn't match a known
address I don't care about."
  (unless (string-match-p
           (rx (or (: "@noreply.github.com" eos)
                   (: "@reply.github.com" eos)
                   (: bos "notifications@github.com" eos)
                   (: "@debbugs.gnu.org" eos)))
           key)
    (funcall oldfun type key text)))
--8<---------------cut here---------------end--------------->8---

Having this as a regular option seems preferable to me, so I'd like to
suggest it here.

In GNU Emacs 29.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.17.6) of 2022-10-13 built on rhea
Repository revision: 0b170c6caeeb669df3cf97c54c43da9cf77e6b42
Repository branch: master
System Description: Fedora Linux 36 (Workstation Edition)

Configured using:
 'configure --with-pgtk --with-imagemagick'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-filtering-what-items-are-added-to-Ecomplete.patch --]
[-- Type: text/patch, Size: 3088 bytes --]

From e03fb00267171fe995f8487043446df18f1f96cf Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Thu, 13 Oct 2022 12:02:02 +0200
Subject: [PATCH] Allow filtering what items are added to Ecomplete

* etc/NEWS: Mention new option.
* lisp/ecomplete.el (ecomplete-filter-regexp): Add new option.
(ecomplete-add-item): Respect new option.
---
 etc/NEWS          |  5 +++++
 lisp/ecomplete.el | 35 +++++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ca857056fd..1357e82810 100644
--- 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
 
 +++
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el
index 6ff67d46d2..21f5f456ea 100644
--- a/lisp/ecomplete.el
+++ b/lisp/ecomplete.el
@@ -86,6 +86,11 @@ ecomplete-auto-select
   :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 @@ ecomplete-add-item
 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."
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#58487: [PATCH] Allow filtering what items are added to Ecomplete
  2022-10-13 10:06 bug#58487: [PATCH] Allow filtering what items are added to Ecomplete Philip Kaludercic
@ 2022-10-13 18:00 ` Lars Ingebrigtsen
  2022-10-14 18:13   ` Philip Kaludercic
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-10-13 18:00 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 58487

Philip Kaludercic <philipk@posteo.net> writes:

> * lisp/ecomplete.el (ecomplete-filter-regexp): Add new option.
> (ecomplete-add-item): Respect new option.

Makes sense to me; please go ahead and push.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#58487: [PATCH] Allow filtering what items are added to Ecomplete
  2022-10-13 18:00 ` Lars Ingebrigtsen
@ 2022-10-14 18:13   ` Philip Kaludercic
  0 siblings, 0 replies; 3+ messages in thread
From: Philip Kaludercic @ 2022-10-14 18:13 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 58487-done

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Philip Kaludercic <philipk@posteo.net> writes:
>
>> * lisp/ecomplete.el (ecomplete-filter-regexp): Add new option.
>> (ecomplete-add-item): Respect new option.
>
> Makes sense to me; please go ahead and push.

Done





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-14 18:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13 10:06 bug#58487: [PATCH] Allow filtering what items are added to Ecomplete Philip Kaludercic
2022-10-13 18:00 ` Lars Ingebrigtsen
2022-10-14 18:13   ` Philip Kaludercic

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).