From 97a312585e7364d9b4e46f744a2ddcf78dafae1f Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Sat, 13 Aug 2016 12:52:33 +0300 Subject: [PATCH] Re: [WIP PATCH] emacs: query: completion for from: in searches --- 90/0ece9e1e3c84f5968adc15329743e6523765a6 | 132 ++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 90/0ece9e1e3c84f5968adc15329743e6523765a6 diff --git a/90/0ece9e1e3c84f5968adc15329743e6523765a6 b/90/0ece9e1e3c84f5968adc15329743e6523765a6 new file mode 100644 index 000000000..6bdec7535 --- /dev/null +++ b/90/0ece9e1e3c84f5968adc15329743e6523765a6 @@ -0,0 +1,132 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 627E96DE3664 + for ; Sat, 13 Aug 2016 02:53:07 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.561 +X-Spam-Level: +X-Spam-Status: No, score=0.561 tagged_above=-999 required=5 tests=[AWL=-0.091, + SPF_NEUTRAL=0.652] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 7_QHVyORGYTA for ; + Sat, 13 Aug 2016 02:52:59 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by arlo.cworth.org (Postfix) with ESMTP id 9B9416DE3663 + for ; Sat, 13 Aug 2016 02:52:58 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id AB0D710007F; + Sat, 13 Aug 2016 12:52:33 +0300 (EEST) +From: Tomi Ollila +To: Mark Walters , notmuch@notmuchmail.org +Subject: Re: [WIP PATCH] emacs: query: completion for from: in searches +In-Reply-To: <1471032242-4701-1-git-send-email-markwalters1009@gmail.com> +References: <1471032242-4701-1-git-send-email-markwalters1009@gmail.com> +User-Agent: Notmuch/0.22+61~geeecb9e (https://notmuchmail.org) Emacs/24.5.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 13 Aug 2016 09:53:07 -0000 + +On Fri, Aug 12 2016, Mark Walters wrote: + +> This is a first attempt at tab completion for from: searches +> --- + +Nice work! I did not test this, but tried to get a grasp of it by +testing tag: completion -- It took me a while to find out where to test +-- in interactive `notmuch-search` invocation, at least... + +I'd be interested in 2 things here: + +1) how to use this feature with external address completion -- how close +can this feature be made to work like address completion when sending +emails + +2) the completion from minibuffer seems to work pretty well -- at least +when comparing how address completion works in +`notmuch-show-resend-message` -- I have to look into that part to see +whether I can improve this... + +Tomi + +> +> This sort of works (well it works but maybe in unexpected ways!) +> +> At the moment it completes to any word (as delimited by whitespace) in +> any address stored in the address hashmap. It does not trigger the +> address harvesting itself -- you either need to call +> notmuch-address-harvest-trigger manually, or use address completion +> when sending a mail first, and the harvest needs to finish before this +> will work. +> +> Since the hashmap does some address deduplication this will not give +> perfect completion (there may be names in your database it won't +> complete to). Also completion is case-sensitive. +> +> Getting a perfect solution may be more effort than its worth -- this +> will probably demonstrate whether something like this suffices. +> +> Best wishes +> +> Mark +> +> emacs/notmuch.el | 18 ++++++++++++++---- +> 1 file changed, 14 insertions(+), 4 deletions(-) +> +> diff --git a/emacs/notmuch.el b/emacs/notmuch.el +> index 8acdef3..532f7b3 100644 +> --- a/emacs/notmuch.el +> +++ b/emacs/notmuch.el +> @@ -888,10 +888,20 @@ PROMPT is the string to prompt with." +> ;; this ugly regexp is used to get the last word of the input +> ;; possibly preceded by a '(' +> ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string) +> - (mapcar (lambda (compl) +> - (concat (match-string-no-properties 1 string) compl)) +> - (all-completions (match-string-no-properties 2 string) +> - completions))) +> + (let ((last-word (match-string-no-properties 2 string)) +> + (start-string (match-string-no-properties 1 string))) +> + (if (and notmuch-address-full-harvest-finished +> + (string-match "^from:\\(.*\\)" last-word)) +> + (let ((from-completions (notmuch-address-matching (match-string 1 last-word)))) +> + (apply #'append +> + (mapcar (lambda (name-addr) +> + (mapcar (lambda (compl) +> + (concat start-string "from:" compl)) +> + (split-string name-addr "[ <>]" t))) +> + from-completions))) +> + (mapcar (lambda (compl) +> + (concat start-string compl)) +> + (all-completions last-word completions))))) +> (t (list string))))))) +> ;; this was simpler than convincing completing-read to accept spaces: +> (define-key keymap (kbd "TAB") 'minibuffer-complete) +> -- +> 2.1.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> https://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2