unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [WIP PATCH] emacs: query: completion for from: in searches
@ 2016-08-12 20:04 Mark Walters
  2016-08-12 23:29 ` Jameson Graef Rollins
  2016-08-13  9:52 ` Tomi Ollila
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Walters @ 2016-08-12 20:04 UTC (permalink / raw)
  To: notmuch

This is a first attempt at tab completion for from: searches
---

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [WIP PATCH] emacs: query: completion for from: in searches
  2016-08-12 20:04 [WIP PATCH] emacs: query: completion for from: in searches Mark Walters
@ 2016-08-12 23:29 ` Jameson Graef Rollins
  2016-08-13  9:52 ` Tomi Ollila
  1 sibling, 0 replies; 3+ messages in thread
From: Jameson Graef Rollins @ 2016-08-12 23:29 UTC (permalink / raw)
  To: Mark Walters, notmuch

[-- Attachment #1: Type: text/plain, Size: 1341 bytes --]

On Fri, Aug 12 2016, Mark Walters <markwalters1009@gmail.com> wrote:
> This is a first attempt at tab completion for from: searches
> ---
>
> 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.

Mark, this patch is awesome.  Really, it works great and is incredibly
useful.  With it I am able to trivially find emails that have
traditionally been very difficult for me to retrieve because the sender
addresses are obscure, e.g. I've only been able to remember a couple
starting characters.

This is on par with the tag: completion for usefulness.  It would be
great to extend this to to: completion as well.

+2

Thanks so much, Mark.

jamie.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [WIP PATCH] emacs: query: completion for from: in searches
  2016-08-12 20:04 [WIP PATCH] emacs: query: completion for from: in searches Mark Walters
  2016-08-12 23:29 ` Jameson Graef Rollins
@ 2016-08-13  9:52 ` Tomi Ollila
  1 sibling, 0 replies; 3+ messages in thread
From: Tomi Ollila @ 2016-08-13  9:52 UTC (permalink / raw)
  To: Mark Walters, notmuch

On Fri, Aug 12 2016, Mark Walters <markwalters1009@gmail.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-13  9:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12 20:04 [WIP PATCH] emacs: query: completion for from: in searches Mark Walters
2016-08-12 23:29 ` Jameson Graef Rollins
2016-08-13  9:52 ` Tomi Ollila

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).