From 82869c1f4f4617b346d8d87a0bb37886d57cc34b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 16 Feb 2022 23:12:43 -0600 Subject: Add ecomplete --- init.el | 13 +++++++++++++ lisp/+ecomplete.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lisp/+ecomplete.el diff --git a/init.el b/init.el index b8d365c..af6daeb 100644 --- a/init.el +++ b/init.el @@ -93,6 +93,19 @@ (:with-mode Custom-mode (:local-set imenu-generic-expression +cus-edit-imenu-generic-expression))) +(setup (:require ecomplete) + (:also-load +ecomplete) + (:option message-mail-alias-type 'ecomplete + message-self-insert-commands nil + message-expand-name-standard-ui t) + (with-eval-after-load 'ecomplete + (:option completion-category-defaults nil) + (with-eval-after-load 'embark + (:bind-into embark-email-map + "+" #'+ecomplete-add-email + "\\" #'+ecomplete-remove-email))) + (add-hook 'message-sent-hook #'message-put-addresses-in-ecomplete)) + (setup (:require goto-addr) (if (fboundp #'global-goto-address-mode) (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 @@ +;;; +ecomplete.el --- ecomplete extras -*- lexical-binding: t; -*- + +;;; Commentary: + +;; see [[https://github.com/oantolin/emacs-config/blob/master/my-lisp/ecomplete-extras.el][oantolin's config]] + +;;; Code: + +(require 'ecomplete) + +(defun +ecomplete--name+address (email) + "Return a pair of the name and address for an EMAIL." + (let (name) + (when (string-match "^\\(?:\\(.*\\) \\)?<\\(.*\\)>$" email) + (setq name (match-string 1 email) + email (match-string 2 email))) + (cons name email))) + +(defun +ecomplete-add-email (email) + "Add email address to ecomplete's database." + (interactive "sEmail address: ") + (pcase-let ((`(,name . ,email) (+ecomplete--name+address email))) + (unless name (setq name (read-string "Name: "))) + (ecomplete-add-item + 'mail email + (format (cond ((equal name "") "%s%s") + ((string-match-p "^\\(?:[A-Za-z0-9 ]*\\|\".*\"\\)$" name) + "%s <%s>") + (t "\"%s\" <%s>")) + name email)) + (ecomplete-save))) + +(defun +ecomplete-remove-email (email) + "Remove email address from ecomplete's database." + (interactive + (list (completing-read "Email address: " + (ecomplete-completion-table 'mail)))) + (when-let ((email (cdr (+ecomplete--name+address email))) + (entry (ecomplete-get-item 'mail email))) + (setf (cdr (assq 'mail ecomplete-database)) + (remove entry (cdr (assq 'mail ecomplete-database)))) + (ecomplete-save))) + +(provide '+ecomplete) +;;; +ecomplete.el ends here -- cgit 1.4.1-21-gabe81