diff options
author | Case Duckworth | 2022-02-16 23:12:43 -0600 |
---|---|---|
committer | Case Duckworth | 2022-02-16 23:12:43 -0600 |
commit | 82869c1f4f4617b346d8d87a0bb37886d57cc34b (patch) | |
tree | 88771768b8d1102b7f425f10c71115bdca656b92 /lisp | |
parent | Use better org faces (diff) | |
download | emacs-82869c1f4f4617b346d8d87a0bb37886d57cc34b.tar.gz emacs-82869c1f4f4617b346d8d87a0bb37886d57cc34b.zip |
Add ecomplete
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+ecomplete.el | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lisp/+ecomplete.el b/lisp/+ecomplete.el new file mode 100644 index 0000000..b1392cf --- /dev/null +++ b/lisp/+ecomplete.el | |||
@@ -0,0 +1,45 @@ | |||
1 | ;;; +ecomplete.el --- ecomplete extras -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Commentary: | ||
4 | |||
5 | ;; see [[https://github.com/oantolin/emacs-config/blob/master/my-lisp/ecomplete-extras.el][oantolin's config]] | ||
6 | |||
7 | ;;; Code: | ||
8 | |||
9 | (require 'ecomplete) | ||
10 | |||
11 | (defun +ecomplete--name+address (email) | ||
12 | "Return a pair of the name and address for an EMAIL." | ||
13 | (let (name) | ||
14 | (when (string-match "^\\(?:\\(.*\\) \\)?<\\(.*\\)>$" email) | ||
15 | (setq name (match-string 1 email) | ||
16 | email (match-string 2 email))) | ||
17 | (cons name email))) | ||
18 | |||
19 | (defun +ecomplete-add-email (email) | ||
20 | "Add email address to ecomplete's database." | ||
21 | (interactive "sEmail address: ") | ||
22 | (pcase-let ((`(,name . ,email) (+ecomplete--name+address email))) | ||
23 | (unless name (setq name (read-string "Name: "))) | ||
24 | (ecomplete-add-item | ||
25 | 'mail email | ||
26 | (format (cond ((equal name "") "%s%s") | ||
27 | ((string-match-p "^\\(?:[A-Za-z0-9 ]*\\|\".*\"\\)$" name) | ||
28 | "%s <%s>") | ||
29 | (t "\"%s\" <%s>")) | ||
30 | name email)) | ||
31 | (ecomplete-save))) | ||
32 | |||
33 | (defun +ecomplete-remove-email (email) | ||
34 | "Remove email address from ecomplete's database." | ||
35 | (interactive | ||
36 | (list (completing-read "Email address: " | ||
37 | (ecomplete-completion-table 'mail)))) | ||
38 | (when-let ((email (cdr (+ecomplete--name+address email))) | ||
39 | (entry (ecomplete-get-item 'mail email))) | ||
40 | (setf (cdr (assq 'mail ecomplete-database)) | ||
41 | (remove entry (cdr (assq 'mail ecomplete-database)))) | ||
42 | (ecomplete-save))) | ||
43 | |||
44 | (provide '+ecomplete) | ||
45 | ;;; +ecomplete.el ends here | ||