From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v1 3/3] emacs: Add an address completer in elisp.
Date: Fri, 5 Sep 2014 13:59:29 +0100 [thread overview]
Message-ID: <1409921969-65129-4-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1409921969-65129-1-git-send-email-dme@dme.org>
Rather than relying on an external comment to provide address
completion in composition mode, provide a solution purely in elisp.
Update `notmuch-address-command' to allow it to specify an external
command or a function, with the default remaining as an external
command called "notmuch-addresses".
---
emacs/notmuch-address.el | 49 +++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 5 deletions(-)
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index fa65cd5..449fa54 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -24,10 +24,17 @@
;;
(defcustom notmuch-address-command "notmuch-addresses"
- "The command which generates possible addresses. It must take a
-single argument and output a list of possible matches, one per
-line."
- :type 'string
+ "Command or function which generates possible addresses.
+
+A command must take a single argument and output a list of
+possible matches, one per line.
+
+A function must take a single argument and return a list of
+possible matches."
+ :type '(choice (string :tag "External command")
+ (function :tag "Standard function"
+ :value notmuch-address-option-generator)
+ (function :tag "Custom function"))
:group 'notmuch-send
:group 'notmuch-external)
@@ -42,6 +49,32 @@ to know how address selection is made by default."
:group 'notmuch-send
:group 'notmuch-external)
+(defun notmuch-address-extractor (message)
+ "Return a list of addresses mentioned in `message'."
+ (let* ((headers (plist-get message :headers))
+ (from (plist-get headers :From)))
+ from))
+
+(defun notmuch-address-option-generator (initial)
+ "Generate a set of possible address completions for `initial'."
+ (let* ((my-addresses (notmuch-user-all-email))
+ (query (list (format "(%s) AND from:%s*"
+ (mapconcat (lambda (a) (concat "to:" a))
+ my-addresses " OR ")
+ initial)))
+ bare-results
+ results)
+ (dolist (address
+ (notmuch-query-map-threads 'notmuch-address-extractor
+ (notmuch-query-get-threads query t t)))
+ (when address
+ (let ((bare-address (cadr (std11-extract-address-components address))))
+ (unless (or (member bare-address my-addresses)
+ (member bare-address bare-results))
+ (push bare-address bare-results)
+ (push address results)))))
+ results))
+
(defun notmuch-address-selection-function (prompt collection initial-input)
"Call (`completing-read'
PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -60,7 +93,13 @@ to know how address selection is made by default."
(push notmuch-address-message-alist-member message-completion-alist))))
(defun notmuch-address-options (original)
- (process-lines notmuch-address-command original))
+ (cond
+ ((stringp notmuch-address-command)
+ (process-lines notmuch-address-command original))
+ ((functionp notmuch-address-command)
+ (funcall notmuch-address-command original))
+ (t
+ (error "No address completion mechanism defined."))))
(defun notmuch-address-expand-name ()
(let* ((end (point))
--
1.8.5.2 (Apple Git-48)
next prev parent reply other threads:[~2014-09-05 12:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-05 12:59 [PATCH v1 0/3] Address completion entirely in elisp David Edmondson
2014-09-05 12:59 ` [PATCH v1 1/3] emacs: Allow query to exclude the entire thread and body David Edmondson
2014-09-05 12:59 ` [PATCH v1 2/3] emacs: Add `notmuch-user-all-email' David Edmondson
2014-09-05 12:59 ` David Edmondson [this message]
2014-09-05 15:29 ` [PATCH v1 0/3] Address completion entirely in elisp Mark Walters
2014-09-05 16:06 ` David Edmondson
2014-09-06 8:14 ` [PATCH] cli: add --output=address-{from,to,all} to notmuch search Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409921969-65129-4-git-send-email-dme@dme.org \
--to=dme@dme.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).