diff options
| author | Philip Kaludercic | 2022-10-13 12:02:02 +0200 |
|---|---|---|
| committer | Philip Kaludercic | 2022-10-14 18:07:53 +0200 |
| commit | cae00567690033308ff06b5d09629e55813c52dd (patch) | |
| tree | 8908500f3c8ee632387322531116f923d6896369 | |
| parent | 6539eb05889c783d782f114d9c072208d3080561 (diff) | |
| download | emacs-cae00567690033308ff06b5d09629e55813c52dd.tar.gz emacs-cae00567690033308ff06b5d09629e55813c52dd.zip | |
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. (bug#58487)
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ecomplete.el | 35 |
2 files changed, 26 insertions, 14 deletions
| @@ -1376,6 +1376,11 @@ the ecomplete database. | |||
| 1376 | *** New user option 'ecomplete-auto-select'. | 1376 | *** New user option 'ecomplete-auto-select'. |
| 1377 | If non-nil and there's only one matching option, auto-select that. | 1377 | If non-nil and there's only one matching option, auto-select that. |
| 1378 | 1378 | ||
| 1379 | --- | ||
| 1380 | *** New user option 'ecomplete-filter-regexp'. | ||
| 1381 | If non-nil this user option describes what email addresses to ignore | ||
| 1382 | and not add to the database. | ||
| 1383 | |||
| 1379 | ** Dired | 1384 | ** Dired |
| 1380 | 1385 | ||
| 1381 | +++ | 1386 | +++ |
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el index 6ff67d46d20..21f5f456ea0 100644 --- a/lisp/ecomplete.el +++ b/lisp/ecomplete.el | |||
| @@ -86,6 +86,11 @@ string that was matched." | |||
| 86 | :type 'boolean | 86 | :type 'boolean |
| 87 | :version "29.1") | 87 | :version "29.1") |
| 88 | 88 | ||
| 89 | (defcustom ecomplete-filter-regexp nil | ||
| 90 | "Regular expression of addresses to not store." | ||
| 91 | :type 'regexp | ||
| 92 | :version "29.1") | ||
| 93 | |||
| 89 | ;;; Internal variables. | 94 | ;;; Internal variables. |
| 90 | 95 | ||
| 91 | (defvar ecomplete-database nil) | 96 | (defvar ecomplete-database nil) |
| @@ -104,20 +109,22 @@ string that was matched." | |||
| 104 | By default, the longest version of TEXT will be preserved, but if | 109 | By default, the longest version of TEXT will be preserved, but if |
| 105 | FORCE is non-nil, use TEXT exactly as is." | 110 | FORCE is non-nil, use TEXT exactly as is." |
| 106 | (unless ecomplete-database (ecomplete-setup)) | 111 | (unless ecomplete-database (ecomplete-setup)) |
| 107 | (let ((elems (assq type ecomplete-database)) | 112 | (unless (and ecomplete-filter-regexp |
| 108 | (now (time-convert nil 'integer)) | 113 | (string-match-p ecomplete-filter-regexp key)) |
| 109 | entry) | 114 | (let ((elems (assq type ecomplete-database)) |
| 110 | (unless elems | 115 | (now (time-convert nil 'integer)) |
| 111 | (push (setq elems (list type)) ecomplete-database)) | 116 | entry) |
| 112 | (if (setq entry (assoc key (cdr elems))) | 117 | (unless elems |
| 113 | (pcase-let ((`(,_key ,count ,_time ,oldtext) entry)) | 118 | (push (setq elems (list type)) ecomplete-database)) |
| 114 | (setcdr entry (list (1+ count) now | 119 | (if (setq entry (assoc key (cdr elems))) |
| 115 | ;; Preserve the "more complete" text. | 120 | (pcase-let ((`(,_key ,count ,_time ,oldtext) entry)) |
| 116 | (if (or force | 121 | (setcdr entry (list (1+ count) now |
| 117 | (>= (length text) (length oldtext))) | 122 | ;; Preserve the "more complete" text. |
| 118 | text | 123 | (if (or force |
| 119 | oldtext)))) | 124 | (>= (length text) (length oldtext))) |
| 120 | (nconc elems (list (list key 1 now text)))))) | 125 | text |
| 126 | oldtext)))) | ||
| 127 | (nconc elems (list (list key 1 now text))))))) | ||
| 121 | 128 | ||
| 122 | (defun ecomplete--remove-item (type key) | 129 | (defun ecomplete--remove-item (type key) |
| 123 | "Remove the element of TYPE and KEY from the ecomplete database." | 130 | "Remove the element of TYPE and KEY from the ecomplete database." |