--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id A5B3A6DE0E46\r
+ for <notmuch@notmuchmail.org>; Fri, 12 Aug 2016 13:04:18 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.349\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.349 tagged_above=-999 required=5 tests=[AWL=0.221,\r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id yQrIBQlDm6-k for <notmuch@notmuchmail.org>;\r
+ Fri, 12 Aug 2016 13:04:10 -0700 (PDT)\r
+Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com\r
+ [74.125.82.68]) by arlo.cworth.org (Postfix) with ESMTPS id 78A786DE0C7E for\r
+ <notmuch@notmuchmail.org>; Fri, 12 Aug 2016 13:04:10 -0700 (PDT)\r
+Received: by mail-wm0-f68.google.com with SMTP id i138so4798759wmf.3\r
+ for <notmuch@notmuchmail.org>; Fri, 12 Aug 2016 13:04:10 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id;\r
+ bh=GZr3F6sGwtqRFy5RPA4xul78VRDsp874PDpb7OzI1Dk=;\r
+ b=N8I9w35B//Lb38RaM16UTZf7bsBNbknXdSlLsCuxvpIo/csKk9H1HBWXFAvY4cxZ+M\r
+ wp53rYQAsE1NF7ws+9cCkmdsvm0qe971EUtHuu44GykTcgeWTvLVmTRz6J70ndkXCRcb\r
+ 2ZiSDtjTmk15O9MIXxohr+wqs8cCooJH7OvI8p0QdJz5pQfKZBfmXZndvfhRmdHWmCS/\r
+ MDsJQmV7LJfaPLdhl4dqVV8ZC0QJc8y1XvMLhNCxU9GoFulyy0XZFxL4L0rMD+LnoLXf\r
+ JJlQXvmzU690o+4SGJ2x81CnX47sVHOsVF/3I/vuN//Ow9aiXLkEu1dWxdmIUAaubtoJ\r
+ NO/Q==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
+ bh=GZr3F6sGwtqRFy5RPA4xul78VRDsp874PDpb7OzI1Dk=;\r
+ b=hMqqKZb3cr6pu6GpilQw49J3t3CY2NGwBJSWxyo9K+ryukn9b0Sylt7Fb4Yoi1bwvs\r
+ ctJOIMzzUs1Ic97Ejj6KSRh36oyS8KalaBmbV7J+zXkJ2oJOLcJaNPbUIAIwRJV4uKGS\r
+ d15zzsJCTdEsSpI4K7/N9uWYSY2jX0pywxf5hGgwWdne1498ZqBkTiIfBDVjSravcQUu\r
+ 2r/OUey4pVCqyPSH94glecp/wwtfI4UI/2DDpYujJP0fJB+z7VWraF3LtXRv0N39NB8w\r
+ bEUF8KCXw/ldJD6MBV0012/DF4nsrkFZVD4NR7VMiA5wYCnIF7pK9jZL+lyd/zPIhLbw\r
+ I4Qg==\r
+X-Gm-Message-State:\r
+ AEkoouuEP5kti+ObZqbAo/nDy6ObuFdWReP5zK3JyeJwXvWZGrFNeLrEZRnsVo9uNv8rJg==\r
+X-Received: by 10.194.127.37 with SMTP id nd5mr17236105wjb.156.1471032248456; \r
+ Fri, 12 Aug 2016 13:04:08 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by smtp.gmail.com with ESMTPSA id pm1sm8913234wjb.40.2016.08.12.13.04.07\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Fri, 12 Aug 2016 13:04:07 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP PATCH] emacs: query: completion for from: in searches\r
+Date: Fri, 12 Aug 2016 21:04:02 +0100\r
+Message-Id: <1471032242-4701-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 2.1.4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 12 Aug 2016 20:04:18 -0000\r
+\r
+This is a first attempt at tab completion for from: searches\r
+---\r
+\r
+This sort of works (well it works but maybe in unexpected ways!)\r
+\r
+At the moment it completes to any word (as delimited by whitespace) in\r
+any address stored in the address hashmap. It does not trigger the\r
+address harvesting itself -- you either need to call\r
+notmuch-address-harvest-trigger manually, or use address completion\r
+when sending a mail first, and the harvest needs to finish before this\r
+will work.\r
+\r
+Since the hashmap does some address deduplication this will not give\r
+perfect completion (there may be names in your database it won't\r
+complete to). Also completion is case-sensitive.\r
+\r
+Getting a perfect solution may be more effort than its worth -- this\r
+will probably demonstrate whether something like this suffices.\r
+\r
+Best wishes\r
+\r
+Mark \r
+\r
+emacs/notmuch.el | 18 ++++++++++++++----\r
+ 1 file changed, 14 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 8acdef3..532f7b3 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -888,10 +888,20 @@ PROMPT is the string to prompt with."\r
+ ;; this ugly regexp is used to get the last word of the input\r
+ ;; possibly preceded by a '('\r
+ ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)\r
+- (mapcar (lambda (compl)\r
+- (concat (match-string-no-properties 1 string) compl))\r
+- (all-completions (match-string-no-properties 2 string)\r
+- completions)))\r
++ (let ((last-word (match-string-no-properties 2 string))\r
++ (start-string (match-string-no-properties 1 string)))\r
++ (if (and notmuch-address-full-harvest-finished\r
++ (string-match "^from:\\(.*\\)" last-word))\r
++ (let ((from-completions (notmuch-address-matching (match-string 1 last-word))))\r
++ (apply #'append\r
++ (mapcar (lambda (name-addr)\r
++ (mapcar (lambda (compl)\r
++ (concat start-string "from:" compl))\r
++ (split-string name-addr "[ <>]" t)))\r
++ from-completions)))\r
++ (mapcar (lambda (compl)\r
++ (concat start-string compl))\r
++ (all-completions last-word completions)))))\r
+ (t (list string)))))))\r
+ ;; this was simpler than convincing completing-read to accept spaces:\r
+ (define-key keymap (kbd "TAB") 'minibuffer-complete)\r
+-- \r
+2.1.4\r
+\r