diff options
-rw-r--r-- | init.el | 13 | ||||
-rw-r--r-- | lisp/+ecomplete.el | 45 |
2 files changed, 58 insertions, 0 deletions
diff --git a/init.el b/init.el index b8d365c..af6daeb 100644 --- a/init.el +++ b/init.el | |||
@@ -93,6 +93,19 @@ | |||
93 | (:with-mode Custom-mode | 93 | (:with-mode Custom-mode |
94 | (:local-set imenu-generic-expression +cus-edit-imenu-generic-expression))) | 94 | (:local-set imenu-generic-expression +cus-edit-imenu-generic-expression))) |
95 | 95 | ||
96 | (setup (:require ecomplete) | ||
97 | (:also-load +ecomplete) | ||
98 | (:option message-mail-alias-type 'ecomplete | ||
99 | message-self-insert-commands nil | ||
100 | message-expand-name-standard-ui t) | ||
101 | (with-eval-after-load 'ecomplete | ||
102 | (:option completion-category-defaults nil) | ||
103 | (with-eval-after-load 'embark | ||
104 | (:bind-into embark-email-map | ||
105 | "+" #'+ecomplete-add-email | ||
106 | "\\" #'+ecomplete-remove-email))) | ||
107 | (add-hook 'message-sent-hook #'message-put-addresses-in-ecomplete)) | ||
108 | |||
96 | (setup (:require goto-addr) | 109 | (setup (:require goto-addr) |
97 | (if (fboundp #'global-goto-address-mode) | 110 | (if (fboundp #'global-goto-address-mode) |
98 | (global-goto-address-mode) | 111 | (global-goto-address-mode) |
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 | ||