From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#58487: [PATCH] Allow filtering what items are added to Ecomplete Date: Thu, 13 Oct 2022 10:06:07 +0000 Message-ID: <877d143unk.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27542"; mail-complaints-to="usenet@ciao.gmane.io" To: 58487@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 13 12:11:40 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oivBj-00073F-BD for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Oct 2022 12:11:39 +0200 Original-Received: from localhost ([::1]:44286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oivBh-00033i-TB for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Oct 2022 06:11:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiv7H-00083t-Eu for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2022 06:07:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60512) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiv7H-0003U1-5U for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2022 06:07:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oiv7G-0005NW-N7 for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2022 06:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Oct 2022 10:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58487 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166565558420609 (code B ref -1); Thu, 13 Oct 2022 10:07:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Oct 2022 10:06:24 +0000 Original-Received: from localhost ([127.0.0.1]:59587 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiv6e-0005ML-CM for submit@debbugs.gnu.org; Thu, 13 Oct 2022 06:06:24 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54642) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiv6c-0005MD-N0 for submit@debbugs.gnu.org; Thu, 13 Oct 2022 06:06:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiv6W-0007I3-AW for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2022 06:06:18 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:51431) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiv6T-0003K7-NN for bug-gnu-emacs@gnu.org; Thu, 13 Oct 2022 06:06:16 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 3C815240105 for ; Thu, 13 Oct 2022 12:06:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1665655571; bh=0yX3I4FD+ThaKEOs/nYG+KhO3ySZgE2lafydO3vtWws=; h=From:To:Subject:Autocrypt:Date:From; b=jbH/q+wuZUemxMMwZAw3J95s9lv5kEywg8LRUqX/PkS7AW5mjTzFhSvPGvvxvF1d9 UOnmgvCZJxpUp6Ga/Rgx8+QmVxfns0al9DJnex2rWT0kNmefs7+tI+v7mkhXu3mYhw rwqSQ8QyamOS6hWmihSVWvfzn/drqJWCPYp8NuWMlKqlo7i0mb2Xa7/R207CvdETYU gAp9mR1Wqb+nTNvTzRk/x7sRMvv2BJ/XZwjmZZQjyXiHeyhJgmJFWe7y8osHO5E9C6 3omVNIai1FANhJhf1xSFy5+HjkGkosPG1JD4KTwycB4UXnD7VCLNVjBGJPKrJ02f1D yAjk1K4YfuWUw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Mp4sr15Fqz9rxH for ; Thu, 13 Oct 2022 12:06:08 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:245284 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Allow-filtering-what-items-are-added-to-Ecomplete.patch >From e03fb00267171fe995f8487043446df18f1f96cf Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-=--