diff options
author | Philip Kaludercic <philipk@posteo.net> | 2022-10-13 12:02:02 +0200 |
---|---|---|
committer | Philip Kaludercic <philipk@posteo.net> | 2022-10-14 18:07:53 +0200 |
commit | cae00567690033308ff06b5d09629e55813c52dd (patch) | |
tree | 8908500f3c8ee632387322531116f923d6896369 /lisp/ecomplete.el | |
parent | 6539eb05889c783d782f114d9c072208d3080561 (diff) | |
download | emacs-cae00567690033308ff06b5d09629e55813c52dd.tar.gz emacs-cae00567690033308ff06b5d09629e55813c52dd.tar.bz2 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)
Diffstat (limited to 'lisp/ecomplete.el')
-rw-r--r-- | lisp/ecomplete.el | 35 |
1 files changed, 21 insertions, 14 deletions
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." :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." |