Re: [PATCH] implement a capf for address completion

2024-03-19 Thread Antoine Beaupré
On 2024-03-19 16:12:04, Antoine Beaupré wrote:

[...]

> The closest we have in the archive is (author in CC):
>
> <71a3382b-3f1b-4b81-883c-b4a8bd710888%40picnicpark.org>
>
> ... which writes a new `kea/notmuch-address-message-capf' function from
> scratch. It might, however, do a better job than i do at taking into
> account the "harvest" process, which I only discovered after writing the
> patch and decided I would pretend it doesn't exist (and is probably
> inaccurate). So that might be a flaw with my patch already, but in my
> defense, WTF is that harvest thing!? :)

Thinking about this more, I *think* the capf *can* return a *function*
instead of a list of strings, so we might be able to refactor this a bit
better and send a function that waits for the harvesting to complete, or
stream the results or something.

Above my pay grade, at this point.

-- 
We have no friends but the mountains.
- Kurdish saying
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] implement a capf for address completion

2024-03-19 Thread Antoine Beaupré
I have *just* realized, after writing all this code and sending the
patch, that someone else might have discussed this here. Oops.

So, turns out, it *has* been discussed, but it doesn't look like anyone
tackled that problem fully just yet.

The closest we have in the archive is (author in CC):

<71a3382b-3f1b-4b81-883c-b4a8bd710888%40picnicpark.org>

... which writes a new `kea/notmuch-address-message-capf' function from
scratch. It might, however, do a better job than i do at taking into
account the "harvest" process, which I only discovered after writing the
patch and decided I would pretend it doesn't exist (and is probably
inaccurate). So that might be a flaw with my patch already, but in my
defense, WTF is that harvest thing!? :)

Another discussion about capf was about integration with EUDC:

<8a437e3f646f7972c86c4aae57ae7452%40condition-alpha.com>

But I don't quite understand what EUDC is or why it matters here. Might
be *some* overlap, not sure.

Finally, there's this whole other thread from 2022 about capf, but it's
quite diffuse and I couldn't make heads or tails of it. The head of the
thread according to the online archives is:



... but that's a reply to... something else, so I'm not sure.

As usual, your mileage may vary. :) To test my patch, you apply it,
restart Emacs (or rewire `message-completion-alist' like Keith Amidon
did), fire off a new email, start entering an address, and hit TAB (or,
if you have corfu, just wait for the timeout).

a.
-- 
We don't need any more heroes.
We just need someone to take out recycling.
- Banksy
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] implement a capf for address completion

2024-03-19 Thread Antoine Beaupré
I recently enabled corfu-mode everywhere, and was disappointed to find
out that I lost tab-completion on my message buffers. At most, corfu
would pop suggestions about existing words in the buffer, but no
address completion, even when I would hit TAB. I believe this is
because `message-tab' won't attempt completion if something else
already did it, and also because, somehow,
`notmuch-address-expand-name' ends up in
`message--old-style-completion-functions'.

Now, it seems to me a simple fix is to implement a proper
capf (`completion-at-point-function') for notmuch. And that, in turn,
is actually pretty simple compared to the code hidden underneath
`notmuch-address-expand-name', which not only finds completion
candidates, but also does the whole trouble of editing the buffer.

So this patch turns `notmuch-address-expand-name' into a wrapper
around the capf, and hooks the capf instead of the old function in the
message-mode completion hooks.

This ... works. Now I have popup completion, automatically (even
before hitting TAB), in my message-mode buffers. It's a bit jarring
because I'm so used to having completion in the minibuffer, but I
think I'll get used to it.

I haven't figured out how to make an escape hatch for this, to get
autocompletion in the minibuffer the same wauy way we did
before. Maybe we'd need something like the
`notmuch-address-from-minibuffer', but interactive somehow. Not
sure. But for now, this allows me to keep corfu globally active, and I
suspect will make things easier and faster going forward.
---
 emacs/notmuch-address.el | 33 +++--
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index f756254c..0c57add8 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -171,7 +171,7 @@ matching `notmuch-address-completion-headers-regexp'."
   (require 'company nil t))
   (notmuch-company-setup))
 (cl-pushnew (cons notmuch-address-completion-headers-regexp
- #'notmuch-address-expand-name)
+ #'notmuch-address-complete-at-point)
message-completion-alist :test #'equal)))
 
 (defun notmuch-address-toggle-internal-completion ()
@@ -225,15 +225,10 @@ requiring external commands."
 (bound-and-true-p company-mode))
 (company-manual-begin))
(notmuch-address-command
-(let* ((end (point))
-  (beg (save-excursion
- (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
- (goto-char (match-end 0))
- (point)))
-  (orig (buffer-substring-no-properties beg end))
-  (completion-ignore-case t)
-  (options (with-temp-message "Looking for completion candidates..."
- (notmuch-address-options orig)))
+(let* ((capf (notmuch-address-complete-at-point))
+  (beg (pop capf))
+  (end (pop capf))
+  (options (pop capf))
   (num-options (length options))
   (chosen (cond
((eq num-options 0)
@@ -256,6 +251,24 @@ requiring external commands."
(ding
(t nil)))
 
+(defun notmuch-address-complete-at-point ()
+  "Complete the address using `notmuch-address-command'.
+
+This replaces the old `notmuch-address-expand-name' with the new
+`completion-at-point-functions' (capf) system that's compatible
+with corfu, company and friends."
+  (when notmuch-address-command
+(let* ((end (point))
+  (beg (save-excursion
+ (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
+ (goto-char (match-end 0))
+ (point)))
+  (orig (buffer-substring-no-properties beg end))
+  (completion-ignore-case t)
+  (options (with-temp-message "Looking for completion candidates..."
+ (notmuch-address-options orig
+  (list beg end options
+
 ;;; Harvest
 
 (defun notmuch-address-harvest-addr (result)
-- 
2.39.2

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: Address Completion in Emacs

2023-12-09 Thread Keith Amidon
This thread inspired me to look a little more deeply into the address 
completion issues I've been having since switching to corfu as well. It 
was a rather long and twisted journey but I ended up getting completion 
using corfu working with the following in my init file:


   ;; Make corfu-based address completion work
   (defun kea/notmuch-address-message-capf ()
 "Return completion data for email addresses in notmuch-address.

Meant for use in `message-completion-alist'."
 (when (and (bound-and-true-p notmuch-address-completions))
   (let ((now (float-time))
 (end (save-excursion
    (skip-chars-forward "^, \t\n")
    (point)))
 (start (save-excursion
  (skip-chars-backward "^, \t\n")
  (point
 (when (> (- now notmuch-address-last-harvest) 86400)
   ;; Synchronously get completions now and update addresses in
   ;; background. Handles startup case where there might not be
   ;; anything in notmuch-address-completions because
   ;; notmuch-address-last-harvest will be 0.
   (notmuch-address-harvest (buffer-substring-no-properties 
start end) t)

   (notmuch-address-harvest-trigger))
 `(,start ,end ,notmuch-address-completions 'mail
   (defun kea/setup-notmuch-message-mode ()
 (setq notmuch-address-use-company nil)
 (setq message-completion-alist
   `((,message-newgroups-header-regexp . ,#'message-expand-group)
 (,message-email-recipient-header-regexp . 
,#'kea/notmuch-address-message-capf

   (add-hook 'notmuch-message-mode-hook #'kea/setup-notmuch-message-mode)

Note that I set mail-user-agent to notmuch-user-agent.

Cheers!   --- Keith

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: Address Completion in Emacs

2023-12-08 Thread David Wen Riccardi-Zhu
Thank you, Sandra! With your advice, I was able to figure out that corfu
was overriding the Tab key from notmuch. If I disable it,
notmuch-address-expand-name works (with orderless and vertico). I'll see
if I can find a way to pipe it into corfu somehow.

Sandra Snan  writes:

> David, I have message-completion-alist set to this value:
>
> (("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
>  
>   .  notmuch-address-expand-name) 
>  ("^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):" . 
>  message-expand-group) ("^\\([^ :]*-\\)?\\(To\\|B?Cc\\|From\\):" . 
>  message-expand-name)) 
>
> That way, when I hit tab in the sender field, which is bound to 
> message-tab, it'll run notmuch-address-expand-name which can find 
> pretty much everyone I've ever heard of.
>
> I additionally have an old BBDB that I've been using for ages that 
> I can access with ESC TAB which is set to bbdb-complete-mail but I 
> literally only have 16 people in there (I just checked). I use 
> them for my most common faves so I can get their most canonical 
> address with just a few letters.
>
> As for weeding through the list of candidates, there are packages 
> such as orderless and vertico that can enhance all calls to 
> completing-read, including the one in notmuch-address-expand-name. 
> After using it a while it does a good job at giving me the 
> relevantest ones at the top and letting me filter through them 
> further.
>
> Corfu and company-mode, I have never heard of! So this is more of 
> an answer to the "alternatively" part you asked.
>
> Sandra
>
>
> David Wen Riccardi-Zhu  writes:
>
>> Hello,
>>
>> I had working address completion in Emacs with company-mode, but
>> recently switched to corfu. Has anyone been able to get address
>> completion to work with it?
>>
>> Alternatively, I'm wondering how the internal completion style works. Is
>> there a function I can call to get internal address completion to kick
>> in?
>>
>> Lastly, is it possible to remove addresses from the list of candidates?
>> I have a few addresses that were consistently recommended even though
>> they had typos in them.
>>
>> I have this in my config:
>>
>> (setq notmuch-address-command 'internal
>>   notmuch-address-internal-completion '(sent nil)
>>   notmuch-address-save-filename "~/org/contacts/notmuch-contacts"
>>   ;; ... 
>> )
>>
>> Can I manually clean up my notmuch-contacts file? 
>>
>> If yes, is it possible to add newlines to the file, to make it easier to
>> search and edit?
>>
>> Thank you!
>>
>> David
>>
>> -- 
>> dwrz|朱为文
>> ___
>> notmuch mailing list -- notmuch@notmuchmail.org
>> To unsubscribe send an email to notmuch-le...@notmuchmail.org

-- 
dwrz|朱为文
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: Address Completion in Emacs

2023-12-08 Thread Sandra Snan

David, I have message-completion-alist set to this value:

(("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):" 
 .  notmuch-address-expand-name) 
("^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):" . 
message-expand-group) ("^\\([^ :]*-\\)?\\(To\\|B?Cc\\|From\\):" . 
message-expand-name)) 

That way, when I hit tab in the sender field, which is bound to 
message-tab, it'll run notmuch-address-expand-name which can find 
pretty much everyone I've ever heard of.


I additionally have an old BBDB that I've been using for ages that 
I can access with ESC TAB which is set to bbdb-complete-mail but I 
literally only have 16 people in there (I just checked). I use 
them for my most common faves so I can get their most canonical 
address with just a few letters.


As for weeding through the list of candidates, there are packages 
such as orderless and vertico that can enhance all calls to 
completing-read, including the one in notmuch-address-expand-name. 
After using it a while it does a good job at giving me the 
relevantest ones at the top and letting me filter through them 
further.


Corfu and company-mode, I have never heard of! So this is more of 
an answer to the "alternatively" part you asked.


Sandra


David Wen Riccardi-Zhu  writes:


Hello,

I had working address completion in Emacs with company-mode, but
recently switched to corfu. Has anyone been able to get address
completion to work with it?

Alternatively, I'm wondering how the internal completion style works. Is
there a function I can call to get internal address completion to kick
in?

Lastly, is it possible to remove addresses from the list of candidates?
I have a few addresses that were consistently recommended even though
they had typos in them.

I have this in my config:

(setq notmuch-address-command 'internal
  notmuch-address-internal-completion '(sent nil)
  notmuch-address-save-filename "~/org/contacts/notmuch-contacts"
  ;; ... 
)


Can I manually clean up my notmuch-contacts file? 


If yes, is it possible to add newlines to the file, to make it easier to
search and edit?

Thank you!

David

--
dwrz|朱为文
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Address Completion in Emacs

2023-12-08 Thread David Wen Riccardi-Zhu
Hello,

I had working address completion in Emacs with company-mode, but
recently switched to corfu. Has anyone been able to get address
completion to work with it?

Alternatively, I'm wondering how the internal completion style works. Is
there a function I can call to get internal address completion to kick
in?

Lastly, is it possible to remove addresses from the list of candidates?
I have a few addresses that were consistently recommended even though
they had typos in them.

I have this in my config:

(setq notmuch-address-command 'internal
  notmuch-address-internal-completion '(sent nil)
  notmuch-address-save-filename "~/org/contacts/notmuch-contacts"
  ;; ... 
)

Can I manually clean up my notmuch-contacts file? 

If yes, is it possible to add newlines to the file, to make it easier to
search and edit?

Thank you!

David

-- 
dwrz|朱为文
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-04-06 Thread David Bremner
Utkarsh Singh  writes:

>>
>> Can you be more precise about what you are asking / proposing here?
>> Assume I only skimmed the thread.
>
> Currently, notmuch-address.el, the library used to generate completion
> candidates for recipient's addresses in Notmuch's message compostion
> mode uses non-standard Emacs API's for in-buffer completion, namely
> completing-read and Company.  Now these API's makes it difficult to
> utilize alternative in-buffer completion UI such as Corfu(1).

#'completing-read is of course standard since forever. We might be using
 it in some strange way, or it might be superceded by better things, but
completing-read is not non-standard.

>
> These are the proposed solutions for the given problem:
>
> 1. Add completion-at-point to the existing sets of frontend.  As noted
> by Tomi, this is a "messy" solution as it unnecessarily obfuscate the
> user options `notmuch-address-selection-function' and
> `notmuch-address-command'.
>
> 2. Make notmuch-address.el itself a backend for EUDC(2).  As stated by
> Alexander, this will not only remove any frontend related code from
> notmuch-address.el, but will also unify completion condidates for other
> sources such as BBDB, LDAP, MacOS Contacts, etc.
>

As a reviewer / release manager, I care about the amount of code
changes. As a user I hope my existing setup will keep working with no,
or (less good) minimal changes. Other than that I am open to ideas.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-04-06 Thread Utkarsh Singh
Hello David,

First of all, apologies for the late reply.  It would have been much
better if Alexander could himself purposed the solution he is developing.

On 2022-03-20, 07:49 -0300, David Bremner  wrote:

> Utkarsh Singh  writes:
>
>> Thank you for working on this issue.  But from now, its up to Notmuch
>> maintainers to decide whether or not they want any improvements in
>> `notmuch-address.el'.
>
> Can you be more precise about what you are asking / proposing here?
> Assume I only skimmed the thread.

Currently, notmuch-address.el, the library used to generate completion
candidates for recipient's addresses in Notmuch's message compostion
mode uses non-standard Emacs API's for in-buffer completion, namely
completing-read and Company.  Now these API's makes it difficult to
utilize alternative in-buffer completion UI such as Corfu(1).

These are the proposed solutions for the given problem:

1. Add completion-at-point to the existing sets of frontend.  As noted
by Tomi, this is a "messy" solution as it unnecessarily obfuscate the
user options `notmuch-address-selection-function' and
`notmuch-address-command'.

2. Make notmuch-address.el itself a backend for EUDC(2).  As stated by
Alexander, this will not only remove any frontend related code from
notmuch-address.el, but will also unify completion condidates for other
sources such as BBDB, LDAP, MacOS Contacts, etc.

Thank you,
Utkarsh Singh

[1]: https://github.com/minad/vertico
[2]: https://www.gnu.org/software/emacs/manual/html_mono/eudc.html

-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-20 Thread David Bremner
Utkarsh Singh  writes:

> Thank you for working on this issue.  But from now, its up to Notmuch
> maintainers to decide whether or not they want any improvements in
> `notmuch-address.el'.

Can you be more precise about what you are asking / proposing here?
Assume I only skimmed the thread.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-16 Thread Utkarsh Singh
On 2022-03-15, 13:37 +0100, Alexander Adolf 
 wrote:

> Utkarsh Singh  writes:
>
>> [...] 
>>>>  `post-completion': Called after a completion candidate has been 
>>>> inserted
>>>>  into the buffer.  The second argument is the candidate.  Can be used 
>>>> to
>>>>  modify it, e.g. to expand a snippet.
>>>> [...]
>>>
>>> Hm, that sounds like it would functionally be similar to specifying an
>>> :exit-function property in completion-extra-properties?
>>
>> Great!  We can definitely work with this.
>> [...]
>
> I'm glad to learn we might be heading in the same direction. AFAIR you
> spoke about removing company from notmuch-address.el altogether? That
> would be by impetus, too.
>
> EUDC [1], which is part of core Emacs, has just been given the ability
> to combine search results from several sources [2].
>
> [1] https://www.gnu.org/software/emacs/manual/html_mono/eudc.html
> [2]  
> https://github.com/emacs-mirror/emacs/commit/0470a4a939772c4bd25123b15f5eadab41f8bee5
>
> I have written experimental code to make EUDC contribute to
> completion-at-point, and to make notmuch-address contribute to EUDC
> search results. This works in principle, and I get combined search
> results from notmuch-address, and the macOS Contacts app in a corfu
> pop-over UI in header fields of message-mode. It seems you were looking
> for something similar?

Honestly, I didn't knew about EUDC, but it looks promising.

> With this kind of setup, the overall architecture for email address
> completion could be like this:
>
> notmuch-address  \  
>BBDB  |  
>LDAP   > --> EUDC --+
>  macOS Contacts  | |
> ...  / V
>|
>   +--<-+
>   |   
>   V   /  completing-read
>   |  |   corfu  
>   + --> completion-at-point --> <company
>  |   ...
>   \
>
> This would remove any user interface related code from
> notmuch-address.el, an instead convert it into a back-end for EUDC.
>
> Looking forward to your thoughts,

Thank you for working on this issue.  But from now, its up to Notmuch
maintainers to decide whether or not they want any improvements in
`notmuch-address.el'.
-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-15 Thread Alexander Adolf
Utkarsh Singh  writes:

> [...] 
>>>  `post-completion': Called after a completion candidate has been 
>>> inserted
>>>  into the buffer.  The second argument is the candidate.  Can be used to
>>>  modify it, e.g. to expand a snippet.
>>> [...]
>>
>> Hm, that sounds like it would functionally be similar to specifying an
>> :exit-function property in completion-extra-properties?
>
> Great!  We can definitely work with this.
> [...]

I'm glad to learn we might be heading in the same direction. AFAIR you
spoke about removing company from notmuch-address.el altogether? That
would be by impetus, too.

EUDC [1], which is part of core Emacs, has just been given the ability
to combine search results from several sources [2].

[1] https://www.gnu.org/software/emacs/manual/html_mono/eudc.html
[2]  
https://github.com/emacs-mirror/emacs/commit/0470a4a939772c4bd25123b15f5eadab41f8bee5

I have written experimental code to make EUDC contribute to
completion-at-point, and to make notmuch-address contribute to EUDC
search results. This works in principle, and I get combined search
results from notmuch-address, and the macOS Contacts app in a corfu
pop-over UI in header fields of message-mode. It seems you were looking
for something similar?

With this kind of setup, the overall architecture for email address
completion could be like this:

notmuch-address  \  
   BBDB  |  
   LDAP   > --> EUDC --+
 macOS Contacts  | |
...  / V
   |
  +--<-+
  |   
  V   /  completing-read
  |  |   corfu  
  + --> completion-at-point --> <company
 |   ...
  \

This would remove any user interface related code from
notmuch-address.el, an instead convert it into a back-end for EUDC.

Looking forward to your thoughts,

  --alexander
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-12 Thread Utkarsh Singh
On 2022-03-11, 18:50 +0100, Alexander Adolf 
 wrote:

> Utkarsh Singh  writes:
>
>> On 2022-03-08, 16:29 +0100, Alexander Adolf 
>>  wrote:
>>
>>> Utkarsh Singh  writes:
>>>
 [...]
 `notmuch-address-post-completion-functions'.
 [...]
>>> [...]
>> Although its a general customization option, here its documentation from
>> company.el:
>>  
>>  `post-completion': Called after a completion candidate has been inserted
>>  into the buffer.  The second argument is the candidate.  Can be used to
>>  modify it, e.g. to expand a snippet.
>> [...]
>
> Hm, that sounds like it would functionally be similar to specifying an
> :exit-function property in completion-extra-properties?

Great!  We can definitely work with this.

> And what could be a use-case for this?

Honestly, I don't have a use-case.  But the goal here is to use standard
Emacs API with least amout of incompatible changes.

-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-11 Thread Alexander Adolf
Utkarsh Singh  writes:

> On 2022-03-08, 16:29 +0100, Alexander Adolf 
>  wrote:
>
>> Utkarsh Singh  writes:
>>
>>> [...]
>>> `notmuch-address-post-completion-functions'.
>>> [...]
>> [...]
> Although its a general customization option, here its documentation from
> company.el:
>  
>  `post-completion': Called after a completion candidate has been inserted
>  into the buffer.  The second argument is the candidate.  Can be used to
>  modify it, e.g. to expand a snippet.
> [...]

Hm, that sounds like it would functionally be similar to specifying an
:exit-function property in completion-extra-properties?

And what could be a use-case for this?


Many thanks in advance and cheers,

  --alexander
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-08 Thread Utkarsh Singh
On 2022-03-08, 16:29 +0100, Alexander Adolf 
 wrote:

> Utkarsh Singh  writes:
>
>> [...]
>> `notmuch-address-post-completion-functions'.
>> [...]
>
> Showing off my lack of understanding: What are they for, and why do we
> need to run something _after_ completion appears to have already
> happened? Would we still need them if company were removed from
> notmuch-address altogether?

Although its a general customization option, here its documentation from
company.el:
 
 `post-completion': Called after a completion candidate has been inserted
 into the buffer.  The second argument is the candidate.  Can be used to
 modify it, e.g. to expand a snippet.
 
-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-07 Thread Alexander Adolf
Utkarsh Singh  writes:

> [...]
> I don't think its possible to modify `notmuch-expand-name' into CAPF
> without breaking backward compatibility.
> [...]

See attached.



patch-notmuch-address.el
Description: application/emacs-lisp
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-03-05 Thread Utkarsh Singh
Hi,

On 2022-02-28, 14:31 +0530, Utkarsh Singh  wrote:

> Currently I'm trying to prepare a patch which will remove all Company
> specific calls with standard Emacs API.  For now, evaluate the following
> expression to review the user-side changes:

I don't think its possible to modify `notmuch-expand-name' into CAPF
without breaking backward compatibility.  But for now, Corfu's users can
use the following hook for the desired behaviour:

(add-hook 'notmuch-message-mode-hook (lambda () (corfu-mode -1)))
-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: emacs: notmuch-address-command 'as-is throws error (was: [PATCH] emacs: Add more front ends for address completion)

2022-03-01 Thread Alexander Adolf
Alexander Adolf  writes:

> [...]
> Variant 2 "core Emacs":
> [...]

It was not as much work as I had anticipated, and hence here is a first
sketch of the idea:



patch-notmuch-address.el
Description: application/emacs-lisp

Some further cleanup to remove all company stuff from notmuch-address.el
would still be needed, though.

Looking forward to your thoughts,

  --alexander
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: emacs: notmuch-address-command 'as-is throws error (was: [PATCH] emacs: Add more front ends for address completion)

2022-02-28 Thread Alexander Adolf
Tomi, apologies for the delay in getting back to you. I'm moving office,
so had a couple of other chores for having fun with. ;-)

Tomi Ollila  writes:

> [...]
>> In case not, how can I prevent modification of message-completion-alist
>> by notmuch, and still have notmuch use the 'internal mechanism for
>> generating address completion candidates?
>
> My guess would be some elisp is required...
> [...]

That's a very good first guess. Always. ;-D

I'm happy to have a go at contributing a patch to enable users to use
completion-at-point for address completion. What would be the least
controversial way forward? I can currently think of two variants.


Variant 1 "minimally invasive surgery":

Adding a new, Boolean custom variable which controls modification of
message-completion-alist. notmuch-address-setup would need to be
modified to make use of it.

Pros: "minimally invasive surgery"

Cons: High entry barrier (the end user needs to define his/her own
  function producing a completion table for email addresses, and
  must hence have a good understanding of how both,
  notmuch-address.el, and completion-at-point work).

  notmuch-address-command 'as-is retains its not too stringently
  defined semantics.


Variant 2 "core Emacs":

Adding a new, choice type custom variable which controls the framework
to use for address completion; possible values are "completing-read
(minibuffer UI)", and "completion-at-point (in-buffer UI)". At the same
time, notmuch-address-use-company and notmuch-address-command 'as-is
would be deprecated. A new function would be added to
notmuch-address.el, which returns a completion table for
completion-at-point. notmuch-address-setup would then need to modified
to add either said new function, or notmuch-address-expand-name to
message-completion-alist, depending on the chosen completion framework
type.

Pros: Uses core Emacs functionality (completing-read, or
  completion-at-point), hence removes dependency on 3rd party
  packages, and thus would make notmuch-address.el (even) more
  future proof.

  High-level configuration option lowers entry barrier for end users
  (no knowledge of notmuch-address.el, or completion-at-point
  required).

Cons: Paves the way for removing company from notmuch-address.el.
  Company can use completion-at-point as a back-end (company-capf),
  so end users can continue to use company if they wish, but need to
  adapt their configuration.



Looking forward to your thoughts,

  --alexander
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-02-28 Thread Utkarsh Singh
Hello Alexander,

On 2022-02-12, 17:09 +0100, Alexander Adolf 
 wrote:

> Tomi Ollila  writes:
>
>> On Tue, Feb 08 2022, Utkarsh Singh wrote:
>>
>>> [...]
>>> Corfu enhances the default completion in region function with a
>>> completion overlay. The current candidates are shown in a popup
>>> below or above the point.  Corfu is the minimalistic
>>> ~completion-in-region~ counterpart of the
>>> [[https://github.com/minad/vertico][Vertico]] minibuffer UI.
>>> [...]
>
> I, too, have been intrigued by this package, and am currently exploring
> it with an eye to replacing the company package for me. I have hit the
> same wall with email address completion in (notmuch) message buffers as
> the OP.
>
> I think there could be a wider question lurking here: apart from
> supporting those completion systems that the developers use, what could
> be a reasonable, overall strategy towards handling completion?
>
> A loosely related case could be indicative: my humble self has written a
> new company back-end for EUDC (Emacs Universal Directory Client), so
> that email addresses from LDAP servers could be offered as completion
> candidates by email clients such as e.g. notmuch. I proposed it to the
> company authors. Their response was that they (trying to word it
> diplomatic here...) would discourage adding any further backends to
> company. Instead, any new completion sources should hook themselves into
> completion-at-point-functions, which in turn can be used as a source for
> candidates by company. In fact, if they re-started company today, they
> would do things completely differently; they'd create a pure UI
> front-end, and use completion-at-point-functions as the one and only
> source; so they said. Sounds a lot like corfu, doesn't it?
>
> The completion topic tends to come up on emacs-devel in certain
> intervals, too. Also there, the same complexity complaints are raised
> against existing completion systems, and the number of fingers pointing
> at completion-at-point-functions seems growing. Ok, not surprising,
> given that it's emacs-devel; but still.
>
> Hence, from my personal point of view, moving _all_ completion to go
> through completion-at-point-functions seems the only reasonable way
> forward.
>
> That would remove any special cases for when company is available from
> the elisp. Fewer third-party integrations, fewer headaches.
>
> I don't think we would loose any functionality, as company can obtain
> candidates from completion-at-point-functions. I.e. users could continue
> to use company w/o losing any functionality. Also, there is a sister
> package to corfu, which is called cape; which is from the same author.
> It allows you to wrap company back-ends so they can be used in
> completion-at-point-functions. This seems a decisive tool for the
> migration to completion-at-point-functions, as it allows users to
> re-purpose existing company back-ends, until their authors will have
> migrated them to completion-at-point-functions.

First of all, apologies for the late reply and thank you for your
interest.

Currently I'm trying to prepare a patch which will remove all Company
specific calls with standard Emacs API.  For now, evaluate the following
expression to review the user-side changes:

(progn
  (add-to-list 'load-path "/usr/share/emacs/site-lisp")
  (require 'notmuch)

  (defun notmuch-address-expand-name ()
(let* ((end (point))
   (beg (save-excursion
  (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
  (goto-char (match-end 0))
  (point)))
   (orig (buffer-substring-no-properties beg end))
   (completion-ignore-case t)
   (options (with-temp-message "Looking for completion candidates..."
  (notmuch-address-options orig
  (list beg end options)))

  (notmuch-mua-new-mail))

-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: emacs: notmuch-address-command 'as-is throws error (was: [PATCH] emacs: Add more front ends for address completion)

2022-02-22 Thread Tomi Ollila
On Mon, Feb 21 2022, Alexander Adolf wrote:

> Alexander Adolf  writes:
>
>> [...]
>> Hence, from my personal point of view, moving _all_ completion to go
>> through completion-at-point-functions seems the only reasonable way
>> forward.
>>
>> That would remove any special cases for when company is available from
>> the elisp. Fewer third-party integrations, fewer headaches.
>> [...]
>
> I have further ventured into this, and am attempting to disable all
> company-related stuff in notmuch-address.el, and instead go through
> completion-at-point-functions, and use corfu as the completion UI.
>
> To achieve this, I have set notmuch-address-use-company to nil, and
> notmuch-address-command to 'as-is.
>
> The latter setting (notmuch-address-command 'as-is) evokes an error:
> "Wrong type argument: stringp, as-is". The backtrace led me to marvel at
> the function notmuch-address-options (in notmuch-address.el). There, in
> case notmuch-address-command is not equal to 'internal, control is
> passed to notmuch--process-lines, which in turn uses 'as-is (a symbol)
> as the name of an external program to call. The name of that command is
> expected to be a string, and hence the "wrong type argument" error.
>
> The docstring for notmuch-address-command does not really state any
> other effects of 'as-is besides preventing modification of
> message-completion-alist (which is what I want, and to keep using the
> internal mechanism). The defcustom option for 'as-is is cunningly
> labelled "Use default or third-party mechanism", which doesn't tell me
> much more either.
>
> Am I misreading notmuch-address.el and/or the docs?

You are probably reading the code right. Probably all the combinations
notmuch-address variables can be set are not (throughly;) tested.

> In case not, how can I prevent modification of message-completion-alist
> by notmuch, and still have notmuch use the 'internal mechanism for
> generating address completion candidates?

My guess would be some elisp is required...

>
> Many thanks in advance and cheers,

>
>   --alexander

cheers, 

Tomi
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


emacs: notmuch-address-command 'as-is throws error (was: [PATCH] emacs: Add more front ends for address completion)

2022-02-21 Thread Alexander Adolf
Alexander Adolf  writes:

> [...]
> Hence, from my personal point of view, moving _all_ completion to go
> through completion-at-point-functions seems the only reasonable way
> forward.
>
> That would remove any special cases for when company is available from
> the elisp. Fewer third-party integrations, fewer headaches.
> [...]

I have further ventured into this, and am attempting to disable all
company-related stuff in notmuch-address.el, and instead go through
completion-at-point-functions, and use corfu as the completion UI.

To achieve this, I have set notmuch-address-use-company to nil, and
notmuch-address-command to 'as-is.

The latter setting (notmuch-address-command 'as-is) evokes an error:
"Wrong type argument: stringp, as-is". The backtrace led me to marvel at
the function notmuch-address-options (in notmuch-address.el). There, in
case notmuch-address-command is not equal to 'internal, control is
passed to notmuch--process-lines, which in turn uses 'as-is (a symbol)
as the name of an external program to call. The name of that command is
expected to be a string, and hence the "wrong type argument" error.

The docstring for notmuch-address-command does not really state any
other effects of 'as-is besides preventing modification of
message-completion-alist (which is what I want, and to keep using the
internal mechanism). The defcustom option for 'as-is is cunningly
labelled "Use default or third-party mechanism", which doesn't tell me
much more either.

Am I misreading notmuch-address.el and/or the docs?

In case not, how can I prevent modification of message-completion-alist
by notmuch, and still have notmuch use the 'internal mechanism for
generating address completion candidates?


Many thanks in advance and cheers,

  --alexander
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [Utkarsh Singh] Re: [PATCH] emacs: Add more front ends for address completion

2022-02-12 Thread Tomi Ollila
On Fri, Feb 11 2022, Utkarsh Singh wrote:

> On 2022-02-10, 19:37 +0200, Tomi Ollila  wrote:
>
>>
>> When doing in notmuch repo, one can execute ./devel/try-emacs-mua -Q
>>
>> ... which probably uses the same package database (under $HOME) as any
>> other emacs invocation would do -- what is the way to change the location
>> of that in order to have chance to have "empty" set of externally installed
>> packages, and messing with it would not touch the "default" packages... 
>
> Okay, we can use `package-user-dir', try the following steps:
>
> 1. Press M-w (`kill-ring-save') to kill/cut the following expression:
>
> --8<---cut here---start->8---
> (progn
>   (setq package-user-dir "/tmp/elpa")
>   (package-initialize)
>   (package-install 'corfu)
>   (package-install 'vertico)
>
>   (require 'notmuch)
>   (require 'corfu)
>   (require 'vertico)
>
>   (vertico-mode 1)
>   (corfu-global-mode 1)
>   (notmuch-mua-new-mail))
> --8<---cut here---end------->8---
>
> 2. Now in ./devel/try-emacs-mua -Q, press M-: (`eval-expression'), C-y
> (`yank') and finally RET.
>
> 3. Press TAB to generate address completion, then press RET to select a
> address, for eg. "Notmuch mailing list ".
> After selection, you will notice that `notmuch-address-expand-name'
> insert desired address with trailing whitespaces.

Yes, I see trailing whitespace.
Also, completion matches only from beginning of the address string.
Also, after one completion TAB no longer completes...

Tomi


>
> --8<---cut here---start->8---
> To: Notmuch mailing list   
> --8<---cut here---end--->8---
>
> I apologize as results are not as reproducible as I thought, but you can
> still notice that `notmuch-address-expand-name' is not producing the
> desired result.
>
> -- 
> Utkarsh Singh
> https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-02-12 Thread Alexander Adolf
Tomi Ollila  writes:

> On Tue, Feb 08 2022, Utkarsh Singh wrote:
>
>> [...]
>> Corfu enhances the default completion in region function with a
>> completion overlay. The current candidates are shown in a popup
>> below or above the point.  Corfu is the minimalistic
>> ~completion-in-region~ counterpart of the
>> [[https://github.com/minad/vertico][Vertico]] minibuffer UI.
>> [...]

I, too, have been intrigued by this package, and am currently exploring
it with an eye to replacing the company package for me. I have hit the
same wall with email address completion in (notmuch) message buffers as
the OP.

I think there could be a wider question lurking here: apart from
supporting those completion systems that the developers use, what could
be a reasonable, overall strategy towards handling completion?

A loosely related case could be indicative: my humble self has written a
new company back-end for EUDC (Emacs Universal Directory Client), so
that email addresses from LDAP servers could be offered as completion
candidates by email clients such as e.g. notmuch. I proposed it to the
company authors. Their response was that they (trying to word it
diplomatic here...) would discourage adding any further backends to
company. Instead, any new completion sources should hook themselves into
completion-at-point-functions, which in turn can be used as a source for
candidates by company. In fact, if they re-started company today, they
would do things completely differently; they'd create a pure UI
front-end, and use completion-at-point-functions as the one and only
source; so they said. Sounds a lot like corfu, doesn't it?

The completion topic tends to come up on emacs-devel in certain
intervals, too. Also there, the same complexity complaints are raised
against existing completion systems, and the number of fingers pointing
at completion-at-point-functions seems growing. Ok, not surprising,
given that it's emacs-devel; but still.

Hence, from my personal point of view, moving _all_ completion to go
through completion-at-point-functions seems the only reasonable way
forward.

That would remove any special cases for when company is available from
the elisp. Fewer third-party integrations, fewer headaches.

I don't think we would loose any functionality, as company can obtain
candidates from completion-at-point-functions. I.e. users could continue
to use company w/o losing any functionality. Also, there is a sister
package to corfu, which is called cape; which is from the same author.
It allows you to wrap company back-ends so they can be used in
completion-at-point-functions. This seems a decisive tool for the
migration to completion-at-point-functions, as it allows users to
re-purpose existing company back-ends, until their authors will have
migrated them to completion-at-point-functions.


Cheers,

  --alexander
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [Utkarsh Singh] Re: [PATCH] emacs: Add more front ends for address completion

2022-02-10 Thread Utkarsh Singh
On 2022-02-10, 19:37 +0200, Tomi Ollila  wrote:

> On Thu, Feb 10 2022, Utkarsh Singh wrote:
>
>>  Start of forwarded message 
>> From: Utkarsh Singh 
>> To: Tomi Ollila 
>> Subject: Re: [PATCH] emacs: Add more front ends for address completion
>> Date: Thu, 10 Feb 2022 08:58:49 +0530
>>
>> Hello Tomi,
>>
>> On 2022-02-09, 23:59 +0200, Tomi Ollila  wrote:
>>
>>> On Tue, Feb 08 2022, Utkarsh Singh wrote:
>>>
>>>> Hello maintainers,
>>>>
>>>> Emacs Lisp Package Archive (ELPA) now includes a package called 'corfu',
>>>> according to its documentation:
>>>>
>>>> Corfu enhances the default completion in region function with a
>>>> completion overlay. The current candidates are shown in a popup
>>>> below or above the point.  Corfu is the minimalistic
>>>> ~completion-in-region~ counterpart of the
>>>> [[https://github.com/minad/vertico][Vertico]] minibuffer UI.
>>>>
>>>> Hence, this patch tries to add support for `completion-in-region' in
>>>> `notmuch-address-expand-name'.  By default, this behaviour is turned off
>>>> so that existing users can enjoy existing completion techniques.
>>>
>>> The current "default" (i.e. w/o any notmuch emacs mua configuration) is to
>>> use completing-read to do the completion. If "company" is available, then
>>> company is used by default (w/ all address harvesting and so on...). 
>>>
>>> This is "messy" enough ;( (i.e the notmuch-address-selection-function
>>> is called if company mode is not available or notmuch-address-command
>>> is a string instead of 'internal or 'as-is (or whatnot, too tired to do
>>> deep investigation there ;/)
>>>
>>> This change, contributes even more "complexity" there. To keep the
>>> complexity to the same level would be adding more
>>> notmuch-address-selection-functions and have the defcustom there list
>>> the options (also probably the name of notmuch-address-selection-function
>>> would need to be changed to notmuch-fallback-address-selection-function
>>> ;/)
>>>
>>
>> I think, in general, you're right about the complexity and we should try
>> minimize it. But this patch was originally derived from a bug I was
>> experiencing with `(global-corfu-mode 1)' in `notmuch-message-mode'.
>
> Is global-corfu-mode changing how completing-read works ?

In theory, no!

>> Here are the steps to reproduce the bug:
>>
>> 1. [Install](https://notmuchmail.org/#index7h2) `notmuch`.
>> 2. In emacs -Q session, evaluate the following
>
> When doing in notmuch repo, one can execute ./devel/try-emacs-mua -Q
>
> ... which probably uses the same package database (under $HOME) as any
> other emacs invocation would do -- what is the way to change the location
> of that in order to have chance to have "empty" set of externally installed
> packages, and messing with it would not touch the "default" packages... 

Okay, we can use `package-user-dir', try the following steps:

1. Press M-w (`kill-ring-save') to kill/cut the following expression:

--8<---cut here---start->8---
(progn
  (setq package-user-dir "/tmp/elpa")
  (package-initialize)
  (package-install 'corfu)
  (package-install 'vertico)

  (require 'notmuch)
  (require 'corfu)
  (require 'vertico)

  (vertico-mode 1)
  (corfu-global-mode 1)
  (notmuch-mua-new-mail))
--8<---cut here---end--->8---

2. Now in ./devel/try-emacs-mua -Q, press M-: (`eval-expression'), C-y
(`yank') and finally RET.

3. Press TAB to generate address completion, then press RET to select a
address, for eg. "Notmuch mailing list ".
After selection, you will notice that `notmuch-address-expand-name'
insert desired address with trailing whitespaces.

--8<---cut here---start->8---
To: Notmuch mailing list   
--8<---cut here---end--->8---

I apologize as results are not as reproducible as I thought, but you can
still notice that `notmuch-address-expand-name' is not producing the
desired result.

-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [Utkarsh Singh] Re: [PATCH] emacs: Add more front ends for address completion

2022-02-10 Thread Tomi Ollila
On Thu, Feb 10 2022, Utkarsh Singh wrote:

>  Start of forwarded message 
> From: Utkarsh Singh 
> To: Tomi Ollila 
> Subject: Re: [PATCH] emacs: Add more front ends for address completion
> Date: Thu, 10 Feb 2022 08:58:49 +0530
>
> Hello Tomi,
>
> On 2022-02-09, 23:59 +0200, Tomi Ollila  wrote:
>
>> On Tue, Feb 08 2022, Utkarsh Singh wrote:
>>
>>> Hello maintainers,
>>>
>>> Emacs Lisp Package Archive (ELPA) now includes a package called 'corfu',
>>> according to its documentation:
>>>
>>> Corfu enhances the default completion in region function with a
>>> completion overlay. The current candidates are shown in a popup
>>> below or above the point.  Corfu is the minimalistic
>>> ~completion-in-region~ counterpart of the
>>> [[https://github.com/minad/vertico][Vertico]] minibuffer UI.
>>>
>>> Hence, this patch tries to add support for `completion-in-region' in
>>> `notmuch-address-expand-name'.  By default, this behaviour is turned off
>>> so that existing users can enjoy existing completion techniques.
>>
>> The current "default" (i.e. w/o any notmuch emacs mua configuration) is to
>> use completing-read to do the completion. If "company" is available, then
>> company is used by default (w/ all address harvesting and so on...). 
>>
>> This is "messy" enough ;( (i.e the notmuch-address-selection-function
>> is called if company mode is not available or notmuch-address-command
>> is a string instead of 'internal or 'as-is (or whatnot, too tired to do
>> deep investigation there ;/)
>>
>> This change, contributes even more "complexity" there. To keep the
>> complexity to the same level would be adding more
>> notmuch-address-selection-functions and have the defcustom there list
>> the options (also probably the name of notmuch-address-selection-function
>> would need to be changed to notmuch-fallback-address-selection-function
>> ;/)
>>
>
> I think, in general, you're right about the complexity and we should try
> minimize it. But this patch was originally derived from a bug I was
> experiencing with `(global-corfu-mode 1)' in `notmuch-message-mode'.

Is global-corfu-mode changing how completing-read works ?

> Here are the steps to reproduce the bug:
>
> 1. [Install](https://notmuchmail.org/#index7h2) `notmuch`.
> 2. In emacs -Q session, evaluate the following

When doing in notmuch repo, one can execute ./devel/try-emacs-mua -Q

... which probably uses the same package database (under $HOME) as any
other emacs invocation would do -- what is the way to change the location
of that in order to have chance to have "empty" set of externally installed
packages, and messing with it would not touch the "default" packages... 

(so that I can try the steps below)

Tomi

>
> ```elisp
> (progn
> (add-to-list 'load-path "/usr/share/emacs/site-lisp") ; Notmuch Emacs 
> interface
> (package-initialize)
> (package-install 'corfu)
> (package-install 'vertico)
>
> (require 'notmuch)
> (require 'corfu)
> (require 'vertico)
>
> (vertico-mode 1)
> (corfu-global-mode 1)
> (notmuch-mua-new-mail))
> ```
>
> 3. Press `TAB` to generate address completion, then press `RET` to
> select address of your choice.  After selection, you will notice that
> `notmuch-address-expand-name` fails to insert desired address, that is,
> you will get the following:
>
> ```
> To:
> ```
>
> Note: Check the trailing spaces.
>
>> All this said, I think this is not simple to solve, as this otherwise fine
>> change would indicate :/
>
> No problem, I'm willing to help the maintainers on this matter.
>
> -- 
> Utkarsh Singh
> https://utkarshsingh.xyz/
>  End of forwarded message 
>
> -- 
> Utkarsh Singh
> https://utkarshsingh.xyz/
> ___
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-le...@notmuchmail.org
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[Utkarsh Singh] Re: [PATCH] emacs: Add more front ends for address completion

2022-02-09 Thread Utkarsh Singh


 Start of forwarded message 
From: Utkarsh Singh 
To: Tomi Ollila 
Subject: Re: [PATCH] emacs: Add more front ends for address completion
Date: Thu, 10 Feb 2022 08:58:49 +0530

Hello Tomi,

On 2022-02-09, 23:59 +0200, Tomi Ollila  wrote:

> On Tue, Feb 08 2022, Utkarsh Singh wrote:
>
>> Hello maintainers,
>>
>> Emacs Lisp Package Archive (ELPA) now includes a package called 'corfu',
>> according to its documentation:
>>
>> Corfu enhances the default completion in region function with a
>> completion overlay. The current candidates are shown in a popup
>> below or above the point.  Corfu is the minimalistic
>> ~completion-in-region~ counterpart of the
>> [[https://github.com/minad/vertico][Vertico]] minibuffer UI.
>>
>> Hence, this patch tries to add support for `completion-in-region' in
>> `notmuch-address-expand-name'.  By default, this behaviour is turned off
>> so that existing users can enjoy existing completion techniques.
>
> The current "default" (i.e. w/o any notmuch emacs mua configuration) is to
> use completing-read to do the completion. If "company" is available, then
> company is used by default (w/ all address harvesting and so on...). 
>
> This is "messy" enough ;( (i.e the notmuch-address-selection-function
> is called if company mode is not available or notmuch-address-command
> is a string instead of 'internal or 'as-is (or whatnot, too tired to do
> deep investigation there ;/)
>
> This change, contributes even more "complexity" there. To keep the
> complexity to the same level would be adding more
> notmuch-address-selection-functions and have the defcustom there list
> the options (also probably the name of notmuch-address-selection-function
> would need to be changed to notmuch-fallback-address-selection-function
> ;/)
>

I think, in general, you're right about the complexity and we should try
minimize it. But this patch was originally derived from a bug I was
experiencing with `(global-corfu-mode 1)' in `notmuch-message-mode'.
Here are the steps to reproduce the bug:

1. [Install](https://notmuchmail.org/#index7h2) `notmuch`.
2. In emacs -Q session, evaluate the following

```elisp
(progn
(add-to-list 'load-path "/usr/share/emacs/site-lisp") ; Notmuch Emacs interface
(package-initialize)
(package-install 'corfu)
(package-install 'vertico)

(require 'notmuch)
(require 'corfu)
(require 'vertico)

(vertico-mode 1)
(corfu-global-mode 1)
(notmuch-mua-new-mail))
```

3. Press `TAB` to generate address completion, then press `RET` to
select address of your choice.  After selection, you will notice that
`notmuch-address-expand-name` fails to insert desired address, that is,
you will get the following:

```
To:
```

Note: Check the trailing spaces.

> All this said, I think this is not simple to solve, as this otherwise fine
> change would indicate :/

No problem, I'm willing to help the maintainers on this matter.

-- 
Utkarsh Singh
https://utkarshsingh.xyz/
 End of forwarded message 

-- 
Utkarsh Singh
https://utkarshsingh.xyz/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] emacs: Add more front ends for address completion

2022-02-09 Thread Tomi Ollila
On Tue, Feb 08 2022, Utkarsh Singh wrote:

> Hello maintainers,
>
> Emacs Lisp Package Archive (ELPA) now includes a package called 'corfu',
> according to its documentation:
>
> Corfu enhances the default completion in region function with a
> completion overlay. The current candidates are shown in a popup
> below or above the point.  Corfu is the minimalistic
> ~completion-in-region~ counterpart of the
> [[https://github.com/minad/vertico][Vertico]] minibuffer UI.
>
> Hence, this patch tries to add support for `completion-in-region' in
> `notmuch-address-expand-name'.  By default, this behaviour is turned off
> so that existing users can enjoy existing completion techniques.

The current "default" (i.e. w/o any notmuch emacs mua configuration) is to
use completing-read to do the completion. If "company" is available, then
company is used by default (w/ all address harvesting and so on...). 

This is "messy" enough ;( (i.e the notmuch-address-selection-function
is called if company mode is not available or notmuch-address-command
is a string instead of 'internal or 'as-is (or whatnot, too tired to do
deep investigation there ;/)

This change, contributes even more "complexity" there. To keep the
complexity to the same level would be adding more
notmuch-address-selection-functions and have the defcustom there list
the options (also probably the name of notmuch-address-selection-function
would need to be changed to notmuch-fallback-address-selection-function
;/)

Also, if name was notmuch-address-selection-function but its interface
changed, current users using their own functions (I am in that list)
would get error there (the interface would have to be
(defun notmuch-address-selection-function (prompt collection initial-input 
 beg end)
to be backward compatible)
If name was changed then their own function would not be used -- which is 
OK, things change and users can read from NEWS how to be compatible
again...

All this said, I think this is not simple to solve, as this otherwise fine
change would indicate :/

Tomi

>
> Thank you,
> Utkarsh Singh
> -- 
> Utkarsh Singh
> https://utkarshsingh.xyz/
> From fdc88b81fef763f7d7dcdc899aa8e90482c574fa Mon Sep 17 00:00:00 2001
> From: Utkarsh Singh 
> Date: Tue, 8 Feb 2022 19:17:26 +0530
> Subject: [PATCH] emacs: Add more front ends for address completion
>
> Add support for address completion through completion-in-region.
> * notmuch-address.el (notmuch-address-use-completion-in-region):
> Introduce customizable variable to activate the new front end.
> (notmuch-address-selection-function, notmuch-address-expand-name): Use
> it.
> ---
>  emacs/notmuch-address.el | 28 ++--
>  1 file changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index 1a4cdda2..cfb56a3a 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -123,10 +123,10 @@ you should make sure it is not somewhere publicly 
> readable."
>  (defcustom notmuch-address-selection-function 
> 'notmuch-address-selection-function
>"The function to select address from given list.
>  
> -The function is called with PROMPT, COLLECTION, and INITIAL-INPUT
> -as arguments (subset of what `completing-read' can be called
> -with).  While executed the value of `completion-ignore-case'
> -is t.  See documentation of function
> +The function is called with PROMPT, COLLECTION, INITIAL-INPUT,
> +BEG and END as arguments (subset of what `completing-read' can be
> +called with).  While executed the value of
> +`completion-ignore-case' is t.  See documentation of function
>  `notmuch-address-selection-function' to know how address
>  selection is made by default."
>:type 'function
> @@ -150,13 +150,19 @@ matching `notmuch-address-completion-headers-regexp'."
>:group 'notmuch-send
>:group 'notmuch-address)
>  
> +(defcustom notmuch-address-use-completion-in-region nil
> +  "Use `completion-in-region' for address completion."
> +  :type 'boolean
> +  :group 'notmuch-send
> +  :group 'notmuch-address)
> +
>  ;;; Setup
>  
> -(defun notmuch-address-selection-function (prompt collection initial-input)
> -  "Call (`completing-read'
> -  PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
> -  (completing-read
> -   prompt collection nil nil initial-input 'notmuch-address-history))
> +(defun notmuch-address-selection-function (prompt collection initial-input 
> beg end)
> +  (if notmuch-address-use-completion-in-region
> +  (completion-in-region beg end collection)
> +(completing-read
> + prompt collection nil ni

[PATCH] emacs: Add more front ends for address completion

2022-02-08 Thread Utkarsh Singh
Hello maintainers,

Emacs Lisp Package Archive (ELPA) now includes a package called 'corfu',
according to its documentation:

Corfu enhances the default completion in region function with a
completion overlay. The current candidates are shown in a popup
below or above the point.  Corfu is the minimalistic
~completion-in-region~ counterpart of the
[[https://github.com/minad/vertico][Vertico]] minibuffer UI.

Hence, this patch tries to add support for `completion-in-region' in
`notmuch-address-expand-name'.  By default, this behaviour is turned off
so that existing users can enjoy existing completion techniques.

Thank you,
Utkarsh Singh
-- 
Utkarsh Singh
https://utkarshsingh.xyz/
>From fdc88b81fef763f7d7dcdc899aa8e90482c574fa Mon Sep 17 00:00:00 2001
From: Utkarsh Singh 
Date: Tue, 8 Feb 2022 19:17:26 +0530
Subject: [PATCH] emacs: Add more front ends for address completion

Add support for address completion through completion-in-region.
* notmuch-address.el (notmuch-address-use-completion-in-region):
Introduce customizable variable to activate the new front end.
(notmuch-address-selection-function, notmuch-address-expand-name): Use
it.
---
 emacs/notmuch-address.el | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1a4cdda2..cfb56a3a 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -123,10 +123,10 @@ you should make sure it is not somewhere publicly readable."
 (defcustom notmuch-address-selection-function 'notmuch-address-selection-function
   "The function to select address from given list.
 
-The function is called with PROMPT, COLLECTION, and INITIAL-INPUT
-as arguments (subset of what `completing-read' can be called
-with).  While executed the value of `completion-ignore-case'
-is t.  See documentation of function
+The function is called with PROMPT, COLLECTION, INITIAL-INPUT,
+BEG and END as arguments (subset of what `completing-read' can be
+called with).  While executed the value of
+`completion-ignore-case' is t.  See documentation of function
 `notmuch-address-selection-function' to know how address
 selection is made by default."
   :type 'function
@@ -150,13 +150,19 @@ matching `notmuch-address-completion-headers-regexp'."
   :group 'notmuch-send
   :group 'notmuch-address)
 
+(defcustom notmuch-address-use-completion-in-region nil
+  "Use `completion-in-region' for address completion."
+  :type 'boolean
+  :group 'notmuch-send
+  :group 'notmuch-address)
+
 ;;; Setup
 
-(defun notmuch-address-selection-function (prompt collection initial-input)
-  "Call (`completing-read'
-  PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
-  (completing-read
-   prompt collection nil nil initial-input 'notmuch-address-history))
+(defun notmuch-address-selection-function (prompt collection initial-input beg end)
+  (if notmuch-address-use-completion-in-region
+  (completion-in-region beg end collection)
+(completing-read
+ prompt collection nil nil initial-input 'notmuch-address-history)))
 
 (defvar notmuch-address-completion-headers-regexp
   "^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):")
@@ -245,7 +251,9 @@ requiring external commands."
 		 (funcall notmuch-address-selection-function
 			  (format "Address (%s matches): " num-options)
 			  options
-			  orig)
+			  orig
+			  beg
+			  end)
   (if chosen
 	  (progn
 	(push chosen notmuch-address-history)
-- 
2.35.1

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH v2 35/36] emacs: allow opting out of notmuch's address completion

2021-01-10 Thread Jonas Bernoulli
IMO Notmuch should not override the default completion mechanism by
default, at least not globally. But since users are already used to
this behavior it is probably too late to change it. Do the next best
thing and at least allow users to opt out.
---
 emacs/notmuch-address.el | 48 +++-
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index ca24c744..6e136473 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -54,21 +54,28 @@ (defun notmuch-address--harvest-ready ()
 (defcustom notmuch-address-command 'internal
   "Determines how address completion candidates are generated.
 
-If it is a string then that string should be an external program
-which must take a single argument (searched string) and output a
-list of completion candidates, one per line.
-
-Alternatively, it can be the symbol `internal', in which case
-internal completion is used; the variable
-`notmuch-address-internal-completion' can be used to customize
-this case.
-
-Finally, if this variable is nil then address completion is
-disabled."
+If this is a string, then that string should be an external
+program, which must take a single argument (searched string)
+and output a list of completion candidates, one per line.
+
+If this is the symbol `internal', then an implementation is used
+that relies on the \"notmuch address\" command, but does not use
+any third-party (i.e. \"external\") programs.
+
+If this is the symbol `as-is', then Notmuch does not modify the
+value of `message-completion-alist'. This option has to be set to
+this value before `notmuch' is loaded, otherwise the modification
+to `message-completion-alist' may already have taken place. This
+setting obviously does not prevent `message-completion-alist'
+from being modified at all; the user or some third-party package
+may still modify it.
+
+Finally, if this is nil, then address completion is disabled."
   :type '(radio
-     (const :tag "Use internal address completion" internal)
-     (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command"))
+ (const  :tag "Use internal address completion" internal)
+ (string :tag "Use external completion command")
+ (const  :tag "Disable address completion" nil)
+ (const  :tag "Use default or third-party mechanism" as-is))
   :group 'notmuch-send
   :group 'notmuch-address
   :group 'notmuch-external)
@@ -160,12 +167,13 @@ (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (when (and notmuch-address-use-company
-(require 'company nil t))
-(notmuch-company-setup))
-  (cl-pushnew (cons notmuch-address-completion-headers-regexp
-   #'notmuch-address-expand-name)
- message-completion-alist :test #'equal))
+  (unless (eq notmuch-address-command 'as-is)
+(when (and notmuch-address-use-company
+  (require 'company nil t))
+  (notmuch-company-setup))
+(cl-pushnew (cons notmuch-address-completion-headers-regexp
+ #'notmuch-address-expand-name)
+   message-completion-alist :test #'equal)))
 
 (defun notmuch-address-toggle-internal-completion ()
   "Toggle use of internal completion for current buffer.
-- 
2.29.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 2/3] emacs: allow opting out of notmuch's address completion

2020-11-08 Thread Jonas Bernoulli
IMO Notmuch should not override the default completion mechanism by
default, at least not globally. But since users are already used to
this behavior it is probably too late to change it. Do the next best
thing and at least allow users to opt out.
---
 emacs/notmuch-address.el | 48 +++-
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 3518beef..6e29b99a 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -52,21 +52,28 @@ (defun notmuch-address--harvest-ready ()
 (defcustom notmuch-address-command 'internal
   "Determines how address completion candidates are generated.
 
-If it is a string then that string should be an external program
-which must take a single argument (searched string) and output a
-list of completion candidates, one per line.
-
-Alternatively, it can be the symbol `internal', in which case
-internal completion is used; the variable
-`notmuch-address-internal-completion' can be used to customize
-this case.
-
-Finally, if this variable is nil then address completion is
-disabled."
+If this is a string, then that string should be an external
+program, which must take a single argument (searched string)
+and output a list of completion candidates, one per line.
+
+If this is the symbol `internal', then an implementation is used
+that relies on the \"notmuch address\" command, but does not use
+any third-party (i.e. \"external\") programs.
+
+If this is the symbol `as-is', then Notmuch does not modify the
+value of `message-completion-alist'. This option has to be set to
+this value before `notmuch' is loaded, otherwise the modification
+to `message-completion-alist' may already have taken place. This
+setting obviously does not prevent `message-completion-alist'
+from being modified at all; the user or some third-party package
+may still modify it.
+
+Finally, if this is nil, then address completion is disabled."
   :type '(radio
-     (const :tag "Use internal address completion" internal)
-     (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command"))
+ (const  :tag "Use internal address completion" internal)
+ (string :tag "Use external completion command")
+ (const  :tag "Disable address completion" nil)
+ (const  :tag "Use default or third-party mechanism" as-is))
   :group 'notmuch-send
   :group 'notmuch-address
   :group 'notmuch-external)
@@ -156,12 +163,13 @@ (defcustom notmuch-address-use-company t
   :group 'notmuch-address)
 
 (defun notmuch-address-setup ()
-  (when (and notmuch-address-use-company
-    (require 'company nil t))
-(notmuch-company-setup))
-  (cl-pushnew (cons notmuch-address-completion-headers-regexp
-   #'notmuch-address-expand-name)
- message-completion-alist :test #'equal))
+  (unless (eq notmuch-address-command 'as-is)
+(when (and notmuch-address-use-company
+  (require 'company nil t))
+  (notmuch-company-setup))
+(cl-pushnew (cons notmuch-address-completion-headers-regexp
+ #'notmuch-address-expand-name)
+   message-completion-alist :test #'equal)))
 
 (defun notmuch-address-toggle-internal-completion ()
   "Toggle use of internal completion for current buffer.
-- 
2.29.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 0/3] emacs: allow opting out of notmuch's address completion

2020-11-08 Thread Jonas Bernoulli
Hello

Notmuch's address completion didn't work well for me.  I read the
respective code and found some issues, some of which are difficult
to address.

I wrote my own implementation, which might eventually be suitable as
a replacement for the current implementation, but it is not ready yet.

In a first step I would like to make it possible to use notmuch and
some other address completion mechanism without having to advice a
notmuch-address.el function to prevent it making destructive changes.
The second commit in this series does that.  Here is the hack I am
currently using instead:

,
| ;;; Counteract notmuch-address.el
| 
| (defun notmuch-address-setup--noop (_fn)
|   "Prevent modification of `message-completion-alist'.")
| (advice-add 'notmuch-address-setup :around
| 'notmuch-address-setup--noop)
`

You can find my implementation (named notmuch-addr.el because it is
like notmuch-address.el, but "smaller") here:

,
| https://git.sr.ht/~tarsius/notmuch-addr
`

The main reason I am not trying to improve that until it can serve as
a replacement for notmuch-address.el is that it depends on Emacs 27.1,
which was just released. (Aside from that it also omits features that
*I* don't need.)

The main reason I am listing defects of notmuch-address.el below is
that by the time we can fix all of them (when we drop support for
Emacs releases before 27.1) I will have forgotten about them, so it
seem like a good idea to document them.

* Emacs' address completion API used to be rather wacky and that was
  not fixed until version 27.1. "Callers" didn't merely have to
  provide a list of completion candidate, instead they actually had to
  perform completion themselves.  Starting with 27.1 the completion-
  at-point API is respected but there are kludges to support the old
  style as well, see https://git.savannah.gnu.org/cgit/emacs.git/com
  mit/?id=47a767c24e9cc4323432e29103b0a2cc46f8f3e4.

  Using capf API has the advantage that many things don't have to be
  re-implemented.  For example `company-mode' just works.  Notmuch
  currently has to implement support explicitly in notmuch-company.el.

* Some essentially random completion candidate is used as the "initial
  input".  The last commit in this series (which see) fixes that.

* The special cases when there is not matching candidate or just a
  single match are handled specifically, which IMO is an optimization
  that makes things worse.  That should also be an easy fix, but since
  it might also be a controversial change, I did not implement it.

* Completion candidates are pre-filered based on the text that was
  already at-point before at-point completion was invoked, which makes
  it possible to choose candidates that that initial text does not
  match.  IMO that's another optimization that badly back fires.

  I was surprised to learn that notmuch shared this feature/defect
  with the current default address implementation in Emacs 27.1.

  The initial commit of my implementation also shares this defect;
  but only so that I can use the second commit to demonstrate how
  that can be fixed.

 Cheers,
 Jonas

Jonas Bernoulli (3):
  emacs: notmuch-address-setup: cosmetics
  emacs: allow opting out of notmuch's address completion
  emacs: notmuch-address-expand-name: use the actual initial-input

 emacs/notmuch-address.el | 57 
 1 file changed, 29 insertions(+), 28 deletions(-)

-- 
2.29.1
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: address completion issues in notmuch-emacs

2019-07-17 Thread David Bremner
"Rollins, Jameson"  writes:

> Hi.  I'm using address completion in notmuch-emacs, but I keep having
> problems.  No matter what "Notmuch Address Internal Completion"
> customization configuration I use ("sent" or "received") there are
> tons of missing addresses that I need.  It seems, though, that the two
> configurations might be compliments of each other, and if I could use
> both sent *and* received then maybe I would get all the addresses I
> need.  Is there some technical reason why the completion doesn't just
> use both?

I don't think so (at least not as an option). It would need an update to
the CLI, or calling "notmuch address" twice.

> I don't understand the parenthetical comments around these options
> either:
>
> ( ) sent (more accurate)
> (*) received (faster)
>
> Why would they have such performance differences?

This as has to do with what is stored in the database (explained in 
notmuch-address(1)).

> And does it really matter at all?  My understanding is that the
> addresses are collected once, so a performance difference at
> collection seem irrelevant to me, since I only care about performance
> when I'm trying to do the actual completion.

That probably depends

1) whether you use the caching. This is off by default due to
   (mild) privacy concerns. It makes another copy of your addresses,
   e.g. on your laptop for people using remote notmuch.

2) if the answer to (1) is no, how often you restart emacs.

But I'd entertain the idea of making "both" default, if backed by some
timing experiments.

Before getting too far into coding/design, it would be nice to know if
the union of those two options contained all the addresses you were
looking for.

Note that there is some other discussion about improving
notmuch-address:

https://github.com/aperezdc/notmuch-addrlookup-c/issues/23

I _think_ that is mainly about better sorting, but I'm not 100%
sure.

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


address completion issues in notmuch-emacs

2019-07-17 Thread Rollins, Jameson
Hi.  I'm using address completion in notmuch-emacs, but I keep having
problems.  No matter what "Notmuch Address Internal Completion"
customization configuration I use ("sent" or "received") there are tons
of missing addresses that I need.  It seems, though, that the two
configurations might be compliments of each other, and if I could use
both sent *and* received then maybe I would get all the addresses I
need.  Is there some technical reason why the completion doesn't just
use both?

I don't understand the parenthetical comments around these options
either:

( ) sent (more accurate)
(*) received (faster)

Why would they have such performance differences?  And does it really
matter at all?  My understanding is that the addresses are collected
once, so a performance difference at collection seem irrelevant to me,
since I only care about performance when I'm trying to do the actual
completion.

jamie.
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: another question : date-limit address completion (or somesuch)?

2018-10-18 Thread Jeff Templon
David Bremner  writes:

> Try M-x customize-variable  notmuch-address-internal-completion

Mind blown!!  Thanks!

JT

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: another question : date-limit address completion (or somesuch)?

2018-10-18 Thread David Bremner
Jeff Templon  writes:

> Hi,
>
> Thanks btw for all the answers to the questions.
>
> I use the tab completion on the To, CC etc fields and like it.  However,
> I have email going back to the nineties, and notmuch TAB completion
> considers all those addresses to be candidates.  It means in many cases
> lots of tabbing work as some of those colleagues have had many addresses
> over the years, and notmuch doesn't always give me the most recent one
> as the first suggestion.
>
> Is there some way to limit which addresses are provided?  I bet that if
> I could limit the completion candidates to all addresses seen in the
> last year, all problems would be gone!

Try M-x customize-variable  notmuch-address-internal-completion

d

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


another question : date-limit address completion (or somesuch)?

2018-10-18 Thread Jeff Templon
Hi,

Thanks btw for all the answers to the questions.

I use the tab completion on the To, CC etc fields and like it.  However,
I have email going back to the nineties, and notmuch TAB completion
considers all those addresses to be candidates.  It means in many cases
lots of tabbing work as some of those colleagues have had many addresses
over the years, and notmuch doesn't always give me the most recent one
as the first suggestion.

Is there some way to limit which addresses are provided?  I bet that if
I could limit the completion candidates to all addresses seen in the
last year, all problems would be gone!

Thanks

JT
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


How to use BBDB address completion instead of internal

2018-04-23 Thread Allan Streib
Hi,

I recently updated from an older version of notmuch, using BBDB for
address book. I don't care for the internal address completion and want
to continue using BBDB. I don't see BBDB as an option for
notmuch-address-command, and if I disable the internal completion I get
no completion at all.

How to I get back to using normal BBDB integration with message-mode?

Thanks,

Allan

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-16 Thread David Bremner
david wen riccardi-zhu  writes:

> Hi David,
>
> My apologies if I am missing something obvious, but I'm getting 
> the following:
>
> Cannot find notmuch-emacs source directory
>
> I've tried running the script from both my home directory and my 
> .emacs.d. The script states:
>
> ;; Try the notmuch emacs client located in ../emacs/ directory
>

I guess you need an unpacked copy of the source to run this. Sorry, I
didn't think that through.

d
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-15 Thread david wen riccardi-zhu

Hi David,

My apologies if I am missing something obvious, but I'm getting 
the following:


Cannot find notmuch-emacs source directory

I've tried running the script from both my home directory and my 
.emacs.d. The script states:


;; Try the notmuch emacs client located in ../emacs/ directory

I'm not sure which directory this is referring to.

Thanks again for your time!
David

David Bremner  writes:

david wen riccardi-zhu  writes: 



Is what I'm seeing potentially a misconfiguration, or bug in 
company-mode? 

The last customizations I made to my init was editing my 
text-mode-hook (where I did specify some company-backends) and 
then just some minor counsel and ripgrep related changes. I 
haven't touched my notmuch-related config in some time. However 
I don't have my init under version control, and it is a mess, 
so perhaps I'm missing something. : ( FWIW, fish is also not a 
recent development. 


The obvious thing to try is try-emacs-mua script from the source 
(attached) 

This will let you use company without any of your personal 
configuration. Run as e.g. "sh ./try-emacs-mua -q" 
 


--
dwrz|朱为文
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-14 Thread David Bremner
david wen riccardi-zhu  writes:

>
> Is what I'm seeing potentially a misconfiguration, or bug in 
> company-mode?
>
> The last customizations I made to my init was editing my 
> text-mode-hook (where I did specify some company-backends) and 
> then just some minor counsel and ripgrep related changes. I 
> haven't touched my notmuch-related config in some time. However I 
> don't have my init under version control, and it is a mess, so 
> perhaps I'm missing something. : ( FWIW, fish is also not a recent 
> development.

The obvious thing to try is try-emacs-mua script from the source
(attached)

This will let you use company without any of your personal
configuration. Run as e.g. "sh ./try-emacs-mua -q"




try-emacs-mua
Description: Binary data
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-12 Thread david wen riccardi-zhu
Thanks, Tomi. So far, I can confirm that completion works with 
emacs -Q, but not with company. I'm looking into that more now.


Tomi Ollila <tomi.oll...@iki.fi> writes:

On Sun, Mar 11 2018, david wen riccardi-zhu wrote: 

Address completion worked out of the box for me with notmuch 
and Emacs. Recently, it's stopped working. I've tried setting 
notmuch-address-command to internal, as well as toggling 
notmuch-address-toggle-internal-completion, but neither has 
been able to return the functionality. 

I am able to get notmuch address to work on the command line. 

I use: Arch Linux X86-64, Kernel 4.15.7-1-ARCH fish shell 
notmuch 0.26 Emacs 25.3.1 company-mode 

Any insights on how I might get autocompletion working again? 


Try running emacs -Q to remove the potential effect of your own 
configuration files (if you have notmuch cloned you can also try 
to execude ./devel/try-emacs-mua to do that). 

If problem persists, resend your issue w/ updated information. 

Tomi 

-- dwrz|朱为文 


--
dwrz|朱为文
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-12 Thread david wen riccardi-zhu

Thanks so much for your time and the suggestions.

- try running (notmuch-address-matching "dwrz") in *scratch* (or 
IELM, 
  or M-:) ; this will eliminate company-mode as a suspect, and 
  potentially give you a traceback if something is going wrong. 


I can confirm this works in IELM and M-:.

- have a look at the variable notmuch-address-save-filename. 
Potentially 
  set it (back) to nil to disable persistent caching. If that 
  fixes it, have a look at the corresponding file, see if 
  something corrupted it.


This was not set to anything, but set or unset, it seems to make 
no difference.


What does seem to make a difference is toggling 
notmuch-address-use-company. Without it, tab completion seems to 
work in message mode, although it's not very useful. With it on, I 
get no completion.


Is what I'm seeing potentially a misconfiguration, or bug in 
company-mode?


The last customizations I made to my init was editing my 
text-mode-hook (where I did specify some company-backends) and 
then just some minor counsel and ripgrep related changes. I 
haven't touched my notmuch-related config in some time. However I 
don't have my init under version control, and it is a mess, so 
perhaps I'm missing something. : ( FWIW, fish is also not a recent 
development.


David Bremner <da...@tethera.net> writes:

david wen riccardi-zhu <d...@dwrz.net> writes: 

Address completion worked out of the box for me with notmuch 
and Emacs. Recently, it's stopped working. I've tried setting 
notmuch-address-command to internal, as well as toggling 
notmuch-address-toggle-internal-completion, but neither has 
been able to return the functionality. 


"stopped working" usually suggests some configuration change to 
me. It would be helpful to know what precisely changed. 

As far as debugging, I had two ideas to try. 

- try running (notmuch-address-matching "dwrz") in *scratch* (or 
IELM, 
  or M-:) ; this will eliminate company-mode as a suspect, and 
  potentially give you a traceback if something is going wrong. 

- have a look at the variable notmuch-address-save-filename. 
Potentially 
  set it (back) to nil to disable persistent caching. If that 
  fixes it, have a look at the corresponding file, see if 
  something corrupted it. 

I use: Arch Linux X86-64, Kernel 4.15.7-1-ARCH fish shell 


fish breaks lots of assumptions for shells, but I guess you 
didn't just switch. 

notmuch 0.26 


some subtle things changed with respect to starting external 
processes in notmuch 0.26; if your recent configuration change 
was upgrading notmuch, that might be worth further 
investigation. 



--
dwrz|朱为文
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-12 Thread Tomi Ollila
On Mon, Mar 12 2018, David Bremner wrote:

> david wen riccardi-zhu <d...@dwrz.net> writes:
>
>> Address completion worked out of the box for me with notmuch and 
>> Emacs. Recently, it's stopped working. I've tried setting 
>> notmuch-address-command to internal, as well as toggling 
>> notmuch-address-toggle-internal-completion, but neither has been 
>> able to return the functionality.
>
> "stopped working" usually suggests some configuration change to me. It
> would be helpful to know what precisely changed.
>
> As far as debugging, I had two ideas to try.
>
> - try running (notmuch-address-matching "dwrz") in *scratch* (or IELM,
>   or M-:) ; this will eliminate company-mode as a suspect, and
>   potentially give you a traceback if something is going wrong.
>
> - have a look at the variable notmuch-address-save-filename. Potentially
>   set it (back) to nil to disable persistent caching. If that fixes it,
>   have a look at the corresponding file, see if something corrupted it.
>
>> I use:
>> Arch Linux X86-64, Kernel 4.15.7-1-ARCH
>> fish shell
>
> fish breaks lots of assumptions for shells, but I guess you didn't just
> switch.

Notmuch Emacs MUA should not rely using any particular $SHELL in any case.
It still uses amdragon's brilliant 
"/bin/sh" "-c" "exec 2>\"$1\"; shift; exec \"$0\" \"$@\"" before emacs 25
and according to make-process' docstring it doesn't use shell (either)...

Also, I tested

$ SHELL=/bin/false ./devel/try-emacs-mua -q

and tried (built-in!) address completion (slow >;), and it worked fine.

>> notmuch 0.26
>
> some subtle things changed with respect to starting external processes
> in notmuch 0.26; if your recent configuration change was upgrading
> notmuch, that might be worth further investigation.

If that is (finally) the case, I'd be interested to know.

Tomi
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-12 Thread David Bremner
david wen riccardi-zhu <d...@dwrz.net> writes:

> Address completion worked out of the box for me with notmuch and 
> Emacs. Recently, it's stopped working. I've tried setting 
> notmuch-address-command to internal, as well as toggling 
> notmuch-address-toggle-internal-completion, but neither has been 
> able to return the functionality.

"stopped working" usually suggests some configuration change to me. It
would be helpful to know what precisely changed.

As far as debugging, I had two ideas to try.

- try running (notmuch-address-matching "dwrz") in *scratch* (or IELM,
  or M-:) ; this will eliminate company-mode as a suspect, and
  potentially give you a traceback if something is going wrong.

- have a look at the variable notmuch-address-save-filename. Potentially
  set it (back) to nil to disable persistent caching. If that fixes it,
  have a look at the corresponding file, see if something corrupted it.

> I use:
> Arch Linux X86-64, Kernel 4.15.7-1-ARCH
> fish shell

fish breaks lots of assumptions for shells, but I guess you didn't just switch.

> notmuch 0.26

some subtle things changed with respect to starting external processes
in notmuch 0.26; if your recent configuration change was upgrading
notmuch, that might be worth further investigation.

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion No Longer Working

2018-03-12 Thread Tomi Ollila
On Sun, Mar 11 2018, david wen riccardi-zhu wrote:

> Address completion worked out of the box for me with notmuch and 
> Emacs. Recently, it's stopped working. I've tried setting 
> notmuch-address-command to internal, as well as toggling 
> notmuch-address-toggle-internal-completion, but neither has been 
> able to return the functionality.
>
> I am able to get notmuch address to work on the command line.
>
> I use:
> Arch Linux X86-64, Kernel 4.15.7-1-ARCH
> fish shell
> notmuch 0.26
> Emacs 25.3.1
> company-mode
>
> Any insights on how I might get autocompletion working again?

Try running emacs -Q to remove the potential effect of your own
configuration files (if you have notmuch cloned you can also
try to execude ./devel/try-emacs-mua to do that).

If problem persists, resend your issue w/ updated information.

Tomi

> --
> dwrz|朱为文
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Address Completion No Longer Working

2018-03-11 Thread david wen riccardi-zhu
Address completion worked out of the box for me with notmuch and 
Emacs. Recently, it's stopped working. I've tried setting 
notmuch-address-command to internal, as well as toggling 
notmuch-address-toggle-internal-completion, but neither has been 
able to return the functionality.


I am able to get notmuch address to work on the command line.

I use:
Arch Linux X86-64, Kernel 4.15.7-1-ARCH
fish shell
notmuch 0.26
Emacs 25.3.1
company-mode

Any insights on how I might get autocompletion working again?
--
dwrz|朱为文
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion

2017-04-18 Thread Jörg Volbers
I've attached a diff which would do the trick. Don't know how to 
contribute 'officially', and I am not much of an elisp guru, so 
that might be a good starter for someone (tm) else.


I guess the problem is not restricted to ivy-mode; other 
completing interfaces like ido might pose the same problem. So it 
could be useful to generalize the approach and introduce a 
function which checks different conditions, instead of checking 
within the let construct. But there's some other stuff to do now 
for me right now. :-)


Jörg


Tomi Ollila  writes:

On Mon, Apr 10 2017, Jörg Volbers  wrote: 

Hello, 

If I press  looking for an address while writing mail, 
vanilla notmuch offers me one preselected candidate. Since I 
use  ivy-mode, this canididate narrows down the list of all 
candidates,  forcing me to delete the initial input (C-a C-k) 
before I can  select among this list. 


Do you use 'internal completion or separate command to find 
completions ? 

If internal, the first choice would be to install `company' 
package from ELPA (I don't know how it works with separate 
command -- which I use, with selection-menu). Company-mode 
provides nice popup where to choose completions from. 

If that is not an option, someone(tm) could provide a patch 
which, based on (fboundp 'ivy-read) uses either ivy-read or 
completing-read, with their specific options for completion 
(what I saw about ivy-read that looks pretty good). OTOH, if 
someone(tm) can show (completing-read ...) which works good as 
is, or when wrapped with ivy, such patches might just be 
tolerated(tm). 

FWIW, I've used the following code in my notmuch setup like 
forever...: 

require 'selection-menu) (setq 
notmuch-address-selection-function 
  (lambda (prompt collection initial-input) 
(selection-menu "Send To:" (cons initial-input 
collection) t))) 
 
Tomi 
 
I currently override this behavior by setting 
notmuch-address-selection-function to my own function: 

 (defun jv-notmuch--address-selection (prompt collection 
 initial-input)  
   (completing-read  
 prompt collection nil nil orig 'notmuch-address-history))  
 (setq notmuch-address-selection-function 
 #'jv-notmuch--address-selection)  

This works as intended. 

Now my question: Is this something specific to ivy-mode, and 
would  it be possible to add an option which simulates the 
above behavior  (basically, using the pre-set variable 'orig' 
instead of  (car-options) in notmuch-address-expand-name), so 
that I do not  need to insert my own function which adds no 
functionality? 

Thanks (also for CC me via PM) 

And by the way, notmuch really is great, thank you for this 
software! 

Jörg 
 
--  http://www.joergvolbers.de 
https://fu-berlin.academia.edu/jvolbers 
___ notmuch mailing 
list notmuch@notmuchmail.org 
https://notmuchmail.org/mailman/listinfo/notmuch 


--
http://www.joergvolbers.de
https://fu-berlin.academia.edu/jvolbers


diff
Description: Datei 'diff'


signature.asc
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Address Completion

2017-04-10 Thread Tomi Ollila
On Mon, Apr 10 2017, Jörg Volbers  wrote:

> Hello,
>
> If I press  looking for an address while writing mail, 
> vanilla notmuch offers me one preselected candidate. Since I use 
> ivy-mode, this canididate narrows down the list of all candidates, 
> forcing me to delete the initial input (C-a C-k)  before I can 
> select among this list.

Do you use 'internal completion or separate command to find completions ?

If internal, the first choice would be to install `company' package from
ELPA (I don't know how it works with separate command -- which I use,
with selection-menu). Company-mode provides nice popup where to choose
completions from.

If that is not an option, someone(tm) could provide a patch which, based
on (fboundp 'ivy-read) uses either ivy-read or completing-read, with their
specific options for completion (what I saw about ivy-read that looks
pretty good). OTOH, if someone(tm) can show (completing-read ...) which
works good as is, or when wrapped with ivy, such patches might just be
tolerated(tm).

FWIW, I've used the following code in my notmuch setup like forever...:

require 'selection-menu)
(setq notmuch-address-selection-function
  (lambda (prompt collection initial-input)
(selection-menu "Send To:" (cons initial-input collection) t)))


Tomi


> I currently override this behavior by setting 
> notmuch-address-selection-function to my own function:
>
>  (defun jv-notmuch--address-selection (prompt collection 
>  initial-input) 
>(completing-read 
>  prompt collection nil nil orig 'notmuch-address-history)) 
>  (setq notmuch-address-selection-function 
>  #'jv-notmuch--address-selection) 
>
> This works as intended.
>
> Now my question: Is this something specific to ivy-mode, and would 
> it be possible to add an option which simulates the above behavior 
> (basically, using the pre-set variable 'orig' instead of 
> (car-options) in notmuch-address-expand-name), so that I do not 
> need to insert my own function which adds no functionality?
>
> Thanks (also for CC me via PM)
>
> And by the way, notmuch really is great, thank you for this 
> software!
>
> Jörg
>
>
> -- 
> http://www.joergvolbers.de
> https://fu-berlin.academia.edu/jvolbers
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Address Completion

2017-04-09 Thread Jörg Volbers

Hello,

If I press  looking for an address while writing mail, 
vanilla notmuch offers me one preselected candidate. Since I use 
ivy-mode, this canididate narrows down the list of all candidates, 
forcing me to delete the initial input (C-a C-k)  before I can 
select among this list.


I currently override this behavior by setting 
notmuch-address-selection-function to my own function:


(defun jv-notmuch--address-selection (prompt collection 
initial-input) 
  (completing-read 
prompt collection nil nil orig 'notmuch-address-history)) 
(setq notmuch-address-selection-function 
#'jv-notmuch--address-selection) 


This works as intended.

Now my question: Is this something specific to ivy-mode, and would 
it be possible to add an option which simulates the above behavior 
(basically, using the pre-set variable 'orig' instead of 
(car-options) in notmuch-address-expand-name), so that I do not 
need to insert my own function which adds no functionality?


Thanks (also for CC me via PM)

And by the way, notmuch really is great, thank you for this 
software!


Jörg


--
http://www.joergvolbers.de
https://fu-berlin.academia.edu/jvolbers


signature.asc
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: rename notmuch-address-completion-hook to notmuch-address-post-completion-functions

2016-11-13 Thread David Bremner
David Bremner  writes:

> Apparently it is a (not completely adhered to) emacs convention [1] that
> only hooks that don't take arguments end in 'hook'
>
> [1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks.html
> ---

pushed to master
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: rename notmuch-address-completion-hook to notmuch-address-post-completion-functions

2016-11-13 Thread David Bremner
Apparently it is a (not completely adhered to) emacs convention [1] that
only hooks that don't take arguments end in 'hook'

[1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks.html
---
 emacs/notmuch-address.el | 4 ++--
 emacs/notmuch-company.el | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 36c796f..5b2beef 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -98,7 +98,7 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
-(defcustom notmuch-address-completion-hook nil
+(defcustom notmuch-address-post-completion-functions nil
   "Functions called after completing address.
 
 The completed address is passed as an argument to each function.
@@ -218,7 +218,7 @@ external commands."
(push chosen notmuch-address-history)
(delete-region beg end)
(insert chosen)
-   (run-hook-with-args 'notmuch-address-completion-hook chosen))
+   (run-hook-with-args 'notmuch-address-post-completion-functions 
chosen))
(message "No matches.")
(ding
(t nil)))
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index 91c4804..b0f9782 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -86,7 +86,7 @@
   (match (if (string-match notmuch-company-last-prefix arg)
 (match-end 0)
   0))
-  (post-completion (run-hook-with-args 'notmuch-address-completion-hook 
arg))
+  (post-completion (run-hook-with-args 
'notmuch-address-post-completion-functions arg))
   (no-cache t
 
 
-- 
2.10.2

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: include first match in address completion

2016-10-09 Thread David Bremner
Mark Walters <markwalters1...@gmail.com> writes:

> The current code for address completion takes the list of possible
> completions (whether generated internally or externally), makes the
> first match the initial value for the completion, and puts all the
> others (but not the first match) into the possible completions.

pushed,

d
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: include first match in address completion

2016-10-09 Thread Mark Walters

On Sun, 09 Oct 2016, David Bremner  wrote:
> Mark Walters  writes:
>
>> This tries to get round most of these problems by including the full
>> list of possible completions, but with the first match moved to the
>> very end of the list.
>
> Have you thought about how this should be adjusted when the completion
> entries are sorted according to some priority? I guess if we treated the
> list circularly putting the highest priority at the end of list would be
> ok. I don't know if that is feasible.

Hi

I hadn't thought about that at all. However, the function
notmuch-address-expand-name just gets a list of possible completions and
from notmuch-address-matching (via notmuch-address-options) and displays
them in the order it receives them. Thus the sorting code goes into
notmuch-address-matching rather than notmuch-address-expand-name, and
hence everything "just works".

This does seem to be the case when I tried on top of my old sort address
patch.

(Note company-mode does its own sort unless not told not to. So at the
moment I think you see an unsorted list of completion candidates if you
are not using company.)

Best wishes

Mark
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: include first match in address completion

2016-10-08 Thread David Bremner
Mark Walters  writes:

> This tries to get round most of these problems by including the full
> list of possible completions, but with the first match moved to the
> very end of the list.

Have you thought about how this should be adjusted when the completion
entries are sorted according to some priority? I guess if we treated the
list circularly putting the highest priority at the end of list would be
ok. I don't know if that is feasible.

d
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-29 Thread David Bremner
Mark Walters  writes:

> ---
>
> I think this fixes the comments for the first version of this (see
> id:1472997204-15411-1-git-send-email-markwalters1...@gmail.com )

pushed to release and master

d
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-28 Thread Tomi Ollila
On Wed, Sep 28 2016, Mark Walters <markwalters1...@gmail.com> wrote:

> ---
>
> I think this fixes the comments for the first version of this (see
> id:1472997204-15411-1-git-send-email-markwalters1...@gmail.com )

yes. +1

>
> Best wishes
>
> Mark
>
> NEWS | 37 +
>  1 file changed, 37 insertions(+)
>
> diff --git a/NEWS b/NEWS
> index 04ab32d..805a034 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -55,6 +55,43 @@ Dump/Restore support for configuration information and 
> properties
>  Emacs
>  -
>  
> +Make notmuch-message-mode use insert for fcc
> +
> +  Notmuch-message-mode now defaults to using notmuch insert for
> +  fcc. The old file based fcc behaviour can be restored by setting the
> +  defcustom `notmuch-maildir-use-notmuch-insert` to nil.
> +
> +  When using notmuch insert, `notmuch-fcc-dirs` must be a subdirectory
> +  of the mailstore (absolute paths are not permitted) followed by any
> +  tag changes to be applied to the inserted message. The tag changes
> +  are applied after the default tagging for new messages. For example
> +  setting the header to "sentmail -inbox +sent" would insert the
> +  message in the subdirectory sentmail of the mailstore, add the tag
> +  "sent", and not add the (normally added) "inbox" tag.
> +
> +  Finally, if the insert fails (e.g. if the database is locked) the
> +  user is presented with the option to retry, ignore, or edit the
> +  header.
> +
> +Make internal address completion customizable
> +
> +  There is a new defcustom `notmuch-address-internal-completion` which
> +  controls how the internal completion works: it allows the user to
> +  choose whether to match on messages the user sent, or the user
> +  received, and to filter the messages used for the match, for example
> +  by date.
> +
> +Allow internal address completion on an individual basis
> +
> +  There is a new function `notmuch-address-toggle-internal-completion`
> +  (by default it has no keybinding) which allows users who normally
> +  use an external completion command to use the builtin internal
> +  completion for the current buffer.
> +
> +  Alternatively, if the user has company-mode enabled, then the user
> +  can use company mode commands such as `company-complete` to
> +  activate the builtin completion for an individual completion.
> +
>  Resend messages
>  
>The function `notmuch-show-resend-message` (bound to `b` in show
> -- 
> 2.1.4
>
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-28 Thread Mark Walters
---

I think this fixes the comments for the first version of this (see
id:1472997204-15411-1-git-send-email-markwalters1...@gmail.com )

Best wishes

Mark

NEWS | 37 +
 1 file changed, 37 insertions(+)

diff --git a/NEWS b/NEWS
index 04ab32d..805a034 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,43 @@ Dump/Restore support for configuration information and 
properties
 Emacs
 -
 
+Make notmuch-message-mode use insert for fcc
+
+  Notmuch-message-mode now defaults to using notmuch insert for
+  fcc. The old file based fcc behaviour can be restored by setting the
+  defcustom `notmuch-maildir-use-notmuch-insert` to nil.
+
+  When using notmuch insert, `notmuch-fcc-dirs` must be a subdirectory
+  of the mailstore (absolute paths are not permitted) followed by any
+  tag changes to be applied to the inserted message. The tag changes
+  are applied after the default tagging for new messages. For example
+  setting the header to "sentmail -inbox +sent" would insert the
+  message in the subdirectory sentmail of the mailstore, add the tag
+  "sent", and not add the (normally added) "inbox" tag.
+
+  Finally, if the insert fails (e.g. if the database is locked) the
+  user is presented with the option to retry, ignore, or edit the
+  header.
+
+Make internal address completion customizable
+
+  There is a new defcustom `notmuch-address-internal-completion` which
+  controls how the internal completion works: it allows the user to
+  choose whether to match on messages the user sent, or the user
+  received, and to filter the messages used for the match, for example
+  by date.
+
+Allow internal address completion on an individual basis
+
+  There is a new function `notmuch-address-toggle-internal-completion`
+  (by default it has no keybinding) which allows users who normally
+  use an external completion command to use the builtin internal
+  completion for the current buffer.
+
+  Alternatively, if the user has company-mode enabled, then the user
+  can use company mode commands such as `company-complete` to
+  activate the builtin completion for an individual completion.
+
 Resend messages
 
   The function `notmuch-show-resend-message` (bound to `b` in show
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: include first match in address completion

2016-09-27 Thread Mark Walters
The current code for address completion takes the list of possible
completions (whether generated internally or externally), makes the
first match the initial value for the completion, and puts all the
others (but not the first match) into the possible completions.

This has the nice effect that the  key takes you immediately to
the next completion (whereas if the first match were included in the
possible completions it would take you to the first match
again).

However, it has two side effects. First, once you have completed to
the full match you find it says and try completing again you get told
"no match" not "sole completion". Secondly, if you delete some of the
text and try completing you don't get the first match as an option.

This tries to get round most of these problems by including the full
list of possible completions, but with the first match moved to the
very end of the list.
---

Jani found this bug/odd behaviour on irc: it shows up particularly
when resending/bouncing a message as we don't have a company mode
option for that yet. It seems that the bahaviour dates back to the
first introduction of address completion in 2010. I don't think this
there is a perfect solution but this seems like an improvement.

Best wishes

Mark


emacs/notmuch-address.el | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 10eaab1..b2e1fba 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -194,7 +194,14 @@ external commands."
(t
 (funcall notmuch-address-selection-function
  (format "Address (%s matches): " num-options)
- (cdr options) (car options))
+ ;; We put the first match as the initial
+ ;; input; we put all the matches as
+ ;; possible completions, moving the
+ ;; first match to the end of the list
+ ;; makes cursor up/down in the list work
+ ;; better.
+ (append (cdr options) (list (car options)))
+ (car options))
   (if chosen
  (progn
(push chosen notmuch-address-history)
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-15 Thread Mark Walters
On Sun, 11 Sep 2016, Jani Nikula  wrote:
> On Sun, 04 Sep 2016, Mark Walters  wrote:
>> +  When using notmuch insert, `notmuch-fcc-dirs` must be a subdirectory
>> +  of the mailstore (absolute paths are not permitted) followed by any
>> +  tag changes to be applied to the inserted message. The tag changes
>> +  are applied after the default tagging for new messages. For example
>> +  setting the header to "sentmail -inbox +sent" would insert the
>> +  message in the subdirectoty sentmail of the mailstore, add the tag
>> +  "sent", and not add the (normally added) "inbox" tag.
>
> Hrmh, bikeshedding after the fact, but this completely deviates from all
> the other tag change customization options in notmuch-emacs. See

Yes it is different, but it is doing something a little different as it
also has the folder to store things in -- and if we want it to be
editable in message mode then essentially it needed to be a string. It
should also mean that the existing "set fcc based on from address" works
including being able to set the tags.

Best wishes

Mark





___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-11 Thread Jani Nikula
On Sun, 04 Sep 2016, Mark Walters  wrote:
> +  When using notmuch insert, `notmuch-fcc-dirs` must be a subdirectory
> +  of the mailstore (absolute paths are not permitted) followed by any
> +  tag changes to be applied to the inserted message. The tag changes
> +  are applied after the default tagging for new messages. For example
> +  setting the header to "sentmail -inbox +sent" would insert the
> +  message in the subdirectoty sentmail of the mailstore, add the tag
> +  "sent", and not add the (normally added) "inbox" tag.

Hrmh, bikeshedding after the fact, but this completely deviates from all
the other tag change customization options in notmuch-emacs. See

notmuch-message-replied-tags
notmuch-archive-tags
notmuch-show-mark-read-tags

BR,
Jani.
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-04 Thread Tomi Ollila
On Sun, Sep 04 2016, Mark Walters <markwalters1...@gmail.com> wrote:

> ---
>
> I am not totally sure about the wording, so any suggestions gratefully
> received.

I don't know about the wording (and perhaps it does not need to be
"perfect") -- just a few other comments (inline).

(almost forgot, but then i saw 'editting' in another email :)

> Best wishes
>
> Mark
>
>
> NEWS | 37 +
>  1 file changed, 37 insertions(+)
>
> diff --git a/NEWS b/NEWS
> index 0221414..af4a712 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -4,6 +4,43 @@ Notmuch 0.23 (UNRELEASED)
>  Emacs
>  -
>  
> +Make message mode use insert for fcc
> +
> +  Message mode now defaults to using notmuch insert for fcc. The old
> +  file based fcc behaviour can be restored by setting the defcustom
> +  `notmuch-maildir-use-notmuch-insert` to nil.
> +
> +  When using notmuch insert, `notmuch-fcc-dirs` must be a subdirectory
> +  of the mailstore (absolute paths are not permitted) followed by any
> +  tag changes to be applied to the inserted message. The tag changes
> +  are applied after the default tagging for new messages. For example
> +  setting the header to "sentmail -inbox +sent" would insert the
> +  message in the subdirectoty sentmail of the mailstore, add the tag

typo -- subdirectory

> +  "sent", and not add the (normally added) "inbox" tag.
> +
> +  Finally, if the insert fails (e.g. if the database is locked)the

space after ')'

> +  user is presented with the option to retry, ignore, or edit the
> +  header.
> +
> +Make address completion customizable

Make internal address completion customizable


> +
> +  There is a new defcustom `notmuch-address-internal-completion` which
> +  controls how the internal completion works: it allows the user to
> +  choose whether to match on messages the user sent, or the user
> +  received, and to filter the messages used for the match, for example
> +  by date.
> +
> +Allow internal address completion on an individual basis
> +
> +  There is a new function `notmuch-address-toggle-internal-completion`
> +  (by default it has no keybinding) which allows users who normally
> +  use an exteranl completion command to use the builtin internal

typo -- external

> +  completion for the current buffer.
> +
> +  Alternatively, if the user has company-mode enabled, then the user
> +  can use company mode commands such as `company-complete` to
> +  activate the builtin completion for an individual completion.
> +
>  Face customization is easier
>  
>New faces `notmuch-search-flagged-face` and
> -- 
> 2.1.4
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] NEWS: add news for fcc insert and address completion changes

2016-09-04 Thread Mark Walters
---

I am not totally sure about the wording, so any suggestions gratefully
received.

Best wishes

Mark


NEWS | 37 +
 1 file changed, 37 insertions(+)

diff --git a/NEWS b/NEWS
index 0221414..af4a712 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,43 @@ Notmuch 0.23 (UNRELEASED)
 Emacs
 -
 
+Make message mode use insert for fcc
+
+  Message mode now defaults to using notmuch insert for fcc. The old
+  file based fcc behaviour can be restored by setting the defcustom
+  `notmuch-maildir-use-notmuch-insert` to nil.
+
+  When using notmuch insert, `notmuch-fcc-dirs` must be a subdirectory
+  of the mailstore (absolute paths are not permitted) followed by any
+  tag changes to be applied to the inserted message. The tag changes
+  are applied after the default tagging for new messages. For example
+  setting the header to "sentmail -inbox +sent" would insert the
+  message in the subdirectoty sentmail of the mailstore, add the tag
+  "sent", and not add the (normally added) "inbox" tag.
+
+  Finally, if the insert fails (e.g. if the database is locked)the
+  user is presented with the option to retry, ignore, or edit the
+  header.
+
+Make address completion customizable
+
+  There is a new defcustom `notmuch-address-internal-completion` which
+  controls how the internal completion works: it allows the user to
+  choose whether to match on messages the user sent, or the user
+  received, and to filter the messages used for the match, for example
+  by date.
+
+Allow internal address completion on an individual basis
+
+  There is a new function `notmuch-address-toggle-internal-completion`
+  (by default it has no keybinding) which allows users who normally
+  use an exteranl completion command to use the builtin internal
+  completion for the current buffer.
+
+  Alternatively, if the user has company-mode enabled, then the user
+  can use company mode commands such as `company-complete` to
+  activate the builtin completion for an individual completion.
+
 Face customization is easier
 
   New faces `notmuch-search-flagged-face` and
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 1/2] emacs: address completion, allow sender/recipient and filters

2016-09-04 Thread David Bremner
Mark Walters <markwalters1...@gmail.com> writes:

> This commit lets the user customize the address completion. It makes
> two changes.

series pushed
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 1/2] emacs: address completion, allow sender/recipient and filters

2016-05-20 Thread Mark Walters
This commit lets the user customize the address completion. It makes
two changes.

The first change controls whether to build the address completion list
based on messages you have sent or you have received (the latter is
much faster).

The second change add a possible filter query to limit the messages
used -- for example, setting this to date:1y..  would limit the
address completions to addresses used in the last year. This speeds up
the address harvest and may also make the search less cluttered as old
addresses may well no longer be valid.
---
 emacs/notmuch-address.el | 135 +--
 emacs/notmuch-company.el |   2 +-
 emacs/notmuch-mua.el |   3 +-
 3 files changed, 98 insertions(+), 42 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index aafbe5f..3e7bdab 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -28,15 +28,62 @@
 ;;
 (declare-function company-manual-begin "company")
 
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
 (defcustom notmuch-address-command 'internal
-  "The command which generates possible addresses. It must take a
-single argument and output a list of possible matches, one per
-line. The default value of `internal' uses built-in address
-completion."
+  "Determines how address completion candidates are generated.
+
+If it is a string then that string should be an external program
+which must take a single argument (searched string) and output a
+list of completion candidates, one per line.
+
+Alternatively, it can be the symbol 'internal, in which case
+internal completion is used; the variable
+`notmuch-address-internal-completion` can be used to customize
+this case.
+
+Finally, if this variable is nil then address completion is
+disabled."
   :type '(radio
  (const :tag "Use internal address completion" internal)
  (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command" "notmuch-addresses"))
+ (string :tag "Use external completion command"))
+  :group 'notmuch-send
+  :group 'notmuch-external)
+
+(defcustom notmuch-address-internal-completion '(sent nil)
+  "Determines how internal address completion generates candidates.
+
+This should be a list of the form '(DIRECTION FILTER), where
+ DIRECTION is either sent or received and specifies whether the
+ candidates are searched in messages sent by the user or received
+ by the user (note received by is much faster), and FILTER is
+ either nil or a filter-string, such as \"date:1y..\" to append
+ to the query."
+  :type '(list :tag "Use internal address completion"
+  (radio
+   :tag "Base completion on messages you have"
+   :value sent
+   (const :tag "sent (more accurate)" sent)
+   (const :tag "received (faster)" received))
+  (radio :tag "Filter messages used for completion"
+ (const :tag "Use all messages" nil)
+ (string :tag "Filter query")))
+  ;; We override set so that we can clear the cache when this changes
+  :set (lambda (symbol value)
+(set-default symbol value)
+(setq notmuch-address-last-harvest 0)
+(setq notmuch-address-completions (clrhash 
notmuch-address-completions))
+(setq notmuch-address-full-harvest-finished nil))
   :group 'notmuch-send
   :group 'notmuch-external)
 
@@ -51,17 +98,6 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
-(defvar notmuch-address-last-harvest 0
-  "Time of last address harvest")
-
-(defvar notmuch-address-completions (make-hash-table :test 'equal)
-  "Hash of email addresses for completion during email composition.
-  This variable is set by calling `notmuch-address-harvest'.")
-
-(defvar notmuch-address-full-harvest-finished nil
-  "t indicates that full completion address harvesting has been
-finished")
-
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -86,9 +122,7 @@ finished")
   (eq notmuch-address-command 'internal)
   (require 'company nil t)))
 (pair (cons notmuch-address-completion-headers-regexp
-   

[PATCH 0/2] Address completion configuration

2016-05-20 Thread Mark Walters
These two patches allow some customization of the notmuch-address
completion.

The first patch is very similar to the patch at
id:1463558813-23603-1-git-send-email-markwalters1...@gmail.com

The second allows the user to use the internal completion on a case by
case basis. Typically this would be useful for users who normally use
some external command for completion, but would like to use the
internal completion when that fails.

This necessitated some changes to the first patch: it made sense to
separate the customisation of the internal address (as this will be
also used for the case by case uses of the internal completion) from
the choice of whether to use internal or external completion by
default. I include the inter-diff of the first patch and the previous
version at
id:1463558813-23603-1-git-send-email-markwalters1...@gmail.com at the
end of this email.

The downside is that it does mean there is an extra defcustom, but the
code is slightly cleaner.

It might make sense to have a keybinding for company-complete
and/or notmuch-address-toggle-internal-completion in
notmuch-mesage-mode but I had no idea what bindings would make sense.

I don't know how many people still use external completion -- but the
extra complexity on top of the previous version is fairly small. Also,
I haven't tested this heavily -- and there are quite a lot of cases.

Best wishes

Mark




Mark Walters (2):
  emacs: address completion, allow sender/recipient and filters
  emacs: address: allow internal completion on an individual basis

 emacs/notmuch-address.el | 154 ++-
 emacs/notmuch-company.el |  10 ++-
 emacs/notmuch-mua.el |   3 +-
 3 files changed, 121 insertions(+), 46 deletions(-)


inter-diff from id:1463558813-23603-1-git-send-email-markwalters1...@gmail.com 

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 62df8ba..3e7bdab 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -39,34 +39,45 @@
   "t indicates that full completion address harvesting has been
 finished")
 
-(defcustom notmuch-address-command '(sent nil)
-  "Determines how to generate address completion candidates.
+(defcustom notmuch-address-command 'internal
+  "Determines how address completion candidates are generated.
 
 If it is a string then that string should be an external program
 which must take a single argument (searched string) and output a
 list of completion candidates, one per line.
 
-Alternatively, it can be a (non-nil) list, in which case internal
-completion is used; in this case the list should have form
-'(DIRECTION FILTER), where DIRECTION is either sent or received
-and specifies whether the candidates are searched in messages
-sent by the user or received by the user (note received by is
-much faster), and FILTER is either nil or a filter-string, such
-as \"date:1y..\" to append to the query.
+Alternatively, it can be the symbol 'internal, in which case
+internal completion is used; the variable
+`notmuch-address-internal-completion` can be used to customize
+this case.
 
-If this variable is nil then address completion is disabled."
+Finally, if this variable is nil then address completion is
+disabled."
   :type '(radio
-     (list :tag "Use internal address completion"
-   (radio
-:tag "Base completion on messages you have"
-:value sent
-(const :tag "sent (more accurate)" sent)
-(const :tag "received (faster)" received))
-   (radio :tag "Filter messages used for completion"
-  (const :tag "Use all messages" nil)
-      (string :tag "Filter query")))
+ (const :tag "Use internal address completion" internal)
  (const :tag "Disable address completion" nil)
  (string :tag "Use external completion command"))
+  :group 'notmuch-send
+  :group 'notmuch-external)
+
+(defcustom notmuch-address-internal-completion '(sent nil)
+  "Determines how internal address completion generates candidates.
+
+This should be a list of the form '(DIRECTION FILTER), where
+ DIRECTION is either sent or received and specifies whether the
+ candidates are searched in messages sent by the user or received
+ by the user (note received by is much faster), and FILTER is
+ either nil or a filter-string, such as \"date:1y..\" to append
+ to the query."
+  :type '(list :tag "Use internal address completion"
+  (radio
+   :tag "Base completion on messages you have"
+   :value sent
+   (const :tag "sent (more accurate)" sent)
+   (const :tag "received (faster)" received))
+  (radio :tag "Filter messages used for completion"
+ (c

Re: [PATCH] emacs: address completion, allow sender/recipient and filters

2016-05-19 Thread Tomi Ollila
On Wed, May 18 2016, Michal Sojka <sojk...@fel.cvut.cz> wrote:

> On Wed, May 18 2016, Mark Walters wrote:
>> This commit lets the user customize the address completion. It makes
>> two changes.
>
> Thanks Mark, now it LGTM.
>
> I configured my address completion to be based on received emails and
> I'm surprised how many variations of my email address is used by
> spammers :)

I tried this and it seems to work. LGTM +1.

Thanks to David's latest pushes I grabbed a little time from my temporarily
busy time and attempted to test this internal address completion...

... for anyone who might be interested, the address harvesting command options
from emacs (without extra filtering) now are.

notmuch 'address' '--format=sexp' '--format-version=2' \
'--output=recipients' '--deduplicate=address' 'from:m...@example.org'

notmuch 'address' '--format=sexp' '--format-version=2' \
'--output=sender' '--deduplicate=address' 'to:m...@example.org'

... I had text here wondering whether this from:/to: is too restrictive
but perhaps it is not. I don't know. Therefore I shut up now :D


Tomi



> Cheers
> -Michal
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: address completion, allow sender/recipient and filters

2016-05-18 Thread Michal Sojka
On Wed, May 18 2016, Mark Walters wrote:
> This commit lets the user customize the address completion. It makes
> two changes.

Thanks Mark, now it LGTM.

I configured my address completion to be based on received emails and
I'm surprised how many variations of my email address is used by
spammers :)

Cheers
-Michal
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: address completion, allow sender/recipient and filters

2016-05-18 Thread Mark Walters
This commit lets the user customize the address completion. It makes
two changes.

The first change controls whether to build the address completion list
based on messages you have sent or you have received (the latter is
much faster).

The second change add a possible filter query to limit the messages
used -- for example, setting this to date:1y..  would limit the
address completions to addresses used in the last year. This speeds up
the address harvest and may also make the search less cluttered as old
addresses may well no longer be valid.
---

This tweaks the commit message and the two docstrings as Michal
suggested, but is otherwise unchanged.

Best wishes

Mark

emacs/notmuch-address.el | 119 ---
 emacs/notmuch-company.el |   2 +-
 2 files changed, 82 insertions(+), 39 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index aafbe5f..62df8ba 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -28,15 +28,51 @@
 ;;
 (declare-function company-manual-begin "company")
 
-(defcustom notmuch-address-command 'internal
-  "The command which generates possible addresses. It must take a
-single argument and output a list of possible matches, one per
-line. The default value of `internal' uses built-in address
-completion."
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
+(defcustom notmuch-address-command '(sent nil)
+  "Determines how to generate address completion candidates.
+
+If it is a string then that string should be an external program
+which must take a single argument (searched string) and output a
+list of completion candidates, one per line.
+
+Alternatively, it can be a (non-nil) list, in which case internal
+completion is used; in this case the list should have form
+'(DIRECTION FILTER), where DIRECTION is either sent or received
+and specifies whether the candidates are searched in messages
+sent by the user or received by the user (note received by is
+much faster), and FILTER is either nil or a filter-string, such
+as \"date:1y..\" to append to the query.
+
+If this variable is nil then address completion is disabled."
   :type '(radio
- (const :tag "Use internal address completion" internal)
+ (list :tag "Use internal address completion"
+   (radio
+:tag "Base completion on messages you have"
+:value sent
+(const :tag "sent (more accurate)" sent)
+(const :tag "received (faster)" received))
+   (radio :tag "Filter messages used for completion"
+      (const :tag "Use all messages" nil)
+  (string :tag "Filter query")))
  (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command" "notmuch-addresses"))
+ (string :tag "Use external completion command"))
+  ;; We override set so that we can clear the cache when this changes
+  :set (lambda (symbol value)
+(set-default symbol value)
+(setq notmuch-address-last-harvest 0)
+(setq notmuch-address-completions (clrhash 
notmuch-address-completions))
+(setq notmuch-address-full-harvest-finished nil))
   :group 'notmuch-send
   :group 'notmuch-external)
 
@@ -51,17 +87,6 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
-(defvar notmuch-address-last-harvest 0
-  "Time of last address harvest")
-
-(defvar notmuch-address-completions (make-hash-table :test 'equal)
-  "Hash of email addresses for completion during email composition.
-  This variable is set by calling `notmuch-address-harvest'.")
-
-(defvar notmuch-address-full-harvest-finished nil
-  "t indicates that full completion address harvesting has been
-finished")
-
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -83,7 +108,8 @@ finished")
 
 (defun notmuch-address-setup ()
   (let* ((use-company (and notmuch-address-use-company
-      (eq notmuch-address-command 'internal)
+  notmuch-address-command
+  (listp notmuch-address-command)
   (require 'company nil t)))
 (pair (cons notmuch-address-completi

[WIP PATCH] Allow user to sort address completion by count

2016-05-17 Thread Mark Walters
---

This is a wip patch which allows the user to sort the address
completions by count. It seems to work but is not heavily
tested. However, I won't have time to work on this for a bit so, since
there was some discussion on irc about this, I thought it worth
posting.

Best wishes

Mark



 emacs/notmuch-address.el | 33 -
 emacs/notmuch-company.el |  3 ++-
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index aafbe5f..0df8a48 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -51,6 +51,12 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defcustom notmuch-address-sort 't
+  "Sort to use for returned address completions"
+  :type 'sexp
+  :group 'notmuch-send
+  :group 'notmuch-external)
+
 (defvar notmuch-address-last-harvest 0
   "Time of last address harvest")
 
@@ -102,9 +108,23 @@ The candidates are taken from 
`notmuch-address-completions'."
(re (regexp-quote substring)))
 (maphash (lambda (key val)
   (when (string-match re key)
-(push key candidates)))
+(push (cons key val) candidates)))
 notmuch-address-completions)
-candidates))
+
+(let ((sorted-candidates
+  (cond ((eq notmuch-address-sort 'alphabetical)
+ (sort candidates (lambda (a b) (string< (car a) (car b)
+((eq notmuch-address-sort 'count)
+ (sort candidates (lambda (a b) (> (cdr a) (cdr b)
+((null notmuch-address-sort) candidates)
+(t
+ (sort candidates
+   (lambda (a b)
+ (or (> (cdr a) (cdr b))
+ (and (= (cdr a) (cdr b))
+  (string< (car a) (car b))
+
+  (mapcar 'car sorted-candidates
 
 (defun notmuch-address-options (original)
   "Returns a list of completion candidates. Uses either
@@ -171,8 +191,10 @@ external commands."
  (throw 'found-command bin
 
 (defun notmuch-address-harvest-addr (result)
-  (let ((name-addr (plist-get result :name-addr)))
-(puthash name-addr t notmuch-address-completions)))
+  (let ((name-addr (plist-get result :name-addr))
+   (count (plist-get result :count)))
+(message "Putting name %s with count %s" name-addr count)
+(puthash name-addr count notmuch-address-completions)))
 
 (defun notmuch-address-harvest-handle-result (obj)
   (notmuch-address-harvest-addr obj))
@@ -201,12 +223,13 @@ time so the address collection runs asynchronously unless
 SYNCHRONOUS is t. In case of asynchronous execution, CALLBACK is
 called when harvesting finishes."
   (let* ((from-me-query (mapconcat (lambda (x) (concat "from:" x)) 
(notmuch-user-emails) " or "))
-(query (if filter-query
+(query (if (stringp filter-query)
(format "(%s) and (%s)" from-me-query filter-query)
  from-me-query))
 (args `("address" "--format=sexp" "--format-version=2"
 "--output=recipients"
 "--deduplicate=address"
+"--output=count"
 ,query)))
 (if synchronous
(mapc #'notmuch-address-harvest-addr
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index b881d6d..bf3c6d8 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -80,7 +80,8 @@
   (match (if (string-match notmuch-company-last-prefix arg)
 (match-end 0)
   0))
-  (no-cache t
+  (no-cache t)
+  (sorted t
 
 
 (provide 'notmuch-company)
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v3] emacs: address completion, allow sender/recipient and filters

2016-05-17 Thread Michal Sojka
Hi Mark,

few minor comments bellow.

On Mon, May 16 2016, Mark Walters wrote:
> This commit lets the user customize the address completion.

Add "It makes two changes."

> The first change controls whether to build the address completion list
> based on messages you have sent or you have received (the latter is
> much faster).
>
> The second change add a possible filter query to limit the messages
> used -- for example, setting this to date:1y..  would limit the
> address completions to addresses used in the last year. This speeds up
> the address harvest and may also make the search less cluttered as old
> addresses may well no longer be valid.
> ---
>
> This version uses the docstrings suggested my Michal (which are much
> better than mine), and renames some variables, as he suggested, to
> make the code clearer.
>
> I wondered about allowing the user to specify completion based on
> message "sent or received", rather than either sent, or received, but
> think that is adding too much mess. We could also allow completion
> based on any messages in the database, which would the include
> completion based on messages received via mailing lists or
> distribution lists.
>
> I also note that if the user enters a bad query into the filter query
> box (eg 6M.. rather than date:6M..) they may get an obscure error as
> notmuch/xapian fails. I don't see a goo way round that so have left
> that as a "don't do that" case.

Agreed.

>  emacs/notmuch-address.el | 119 
> ---
>  emacs/notmuch-company.el |   2 +-
>  2 files changed, 82 insertions(+), 39 deletions(-)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index aafbe5f..3dc5da9 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -28,15 +28,51 @@
>  ;;
>  (declare-function company-manual-begin "company")
>  
> -(defcustom notmuch-address-command 'internal
> -  "The command which generates possible addresses. It must take a
> -single argument and output a list of possible matches, one per
> -line. The default value of `internal' uses built-in address
> -completion."
> +(defvar notmuch-address-last-harvest 0
> +  "Time of last address harvest")
> +
> +(defvar notmuch-address-completions (make-hash-table :test 'equal)
> +  "Hash of email addresses for completion during email composition.
> +  This variable is set by calling `notmuch-address-harvest'.")
> +
> +(defvar notmuch-address-full-harvest-finished nil
> +  "t indicates that full completion address harvesting has been
> +finished")
> +
> +(defcustom notmuch-address-command '(sent nil)
> +  "Determines how to generate address completion candidates.
> +
> +If it is a string then that string should be an external program
> +which must take a single argument (searched string) and output a
> +list of completion candidates, one per line.
> +
> +Alternatively, it can be a (non-nil) list, in which case internal
> +completion is used; in this case the list should have form
> +'(DIRECTION FILTER), where DIRECTION is either sent or received
> +and specifies whether the candidates are searched in messages
> +sent by the user or received by the user (note received by is
> +much faster), and FILTER is either nil or a filter-string, such
> +as \"date:1y..\" to append to the query.
> +
> +If this variable is nil then address completion is disabled."
>:type '(radio
> -   (const :tag "Use internal address completion" internal)
> +   (list :tag "Use internal address completion"
> + (radio
> +  :tag "Base completion on messages you have"
> +  :value sent
> +  (const :tag "sent" sent)
> +  (const :tag "received" received))

I think, users will be more happy if they understand the difference
without reading the full doc string.

 (const :tag "sent (more accurate)" sent)
 (const :tag "received (faster)" received))


Thanks.
-Michal
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3] emacs: address completion, allow sender/recipient and filters

2016-05-16 Thread Mark Walters
This commit lets the user customize the address completion.

The first change controls whether to build the address completion list
based on messages you have sent or you have received (the latter is
much faster).

The second change add a possible filter query to limit the messages
used -- for example, setting this to date:1y..  would limit the
address completions to addresses used in the last year. This speeds up
the address harvest and may also make the search less cluttered as old
addresses may well no longer be valid.
---

This version uses the docstrings suggested my Michal (which are much
better than mine), and renames some variables, as he suggested, to
make the code clearer.

I wondered about allowing the user to specify completion based on
message "sent or received", rather than either sent, or received, but
think that is adding too much mess. We could also allow completion
based on any messages in the database, which would the include
completion based on messages received via mailing lists or
distribution lists.

I also note that if the user enters a bad query into the filter query
box (eg 6M.. rather than date:6M..) they may get an obscure error as
notmuch/xapian fails. I don't see a goo way round that so have left
that as a "don't do that" case.

Best wishes

Mark


 emacs/notmuch-address.el | 119 ---
 emacs/notmuch-company.el |   2 +-
 2 files changed, 82 insertions(+), 39 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index aafbe5f..3dc5da9 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -28,15 +28,51 @@
 ;;
 (declare-function company-manual-begin "company")
 
-(defcustom notmuch-address-command 'internal
-  "The command which generates possible addresses. It must take a
-single argument and output a list of possible matches, one per
-line. The default value of `internal' uses built-in address
-completion."
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
+(defcustom notmuch-address-command '(sent nil)
+  "Determines how to generate address completion candidates.
+
+If it is a string then that string should be an external program
+which must take a single argument (searched string) and output a
+list of completion candidates, one per line.
+
+Alternatively, it can be a (non-nil) list, in which case internal
+completion is used; in this case the list should have form
+'(DIRECTION FILTER), where DIRECTION is either sent or received
+and specifies whether the candidates are searched in messages
+sent by the user or received by the user (note received by is
+much faster), and FILTER is either nil or a filter-string, such
+as \"date:1y..\" to append to the query.
+
+If this variable is nil then address completion is disabled."
   :type '(radio
- (const :tag "Use internal address completion" internal)
+ (list :tag "Use internal address completion"
+   (radio
+:tag "Base completion on messages you have"
+:value sent
+(const :tag "sent" sent)
+(const :tag "received" received))
+   (radio :tag "Filter messages used for completion"
+      (const :tag "Use all messages" nil)
+  (string :tag "Filter query")))
  (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command" "notmuch-addresses"))
+ (string :tag "Use external completion command"))
+  ;; We override set so that we can clear the cache when this changes
+  :set (lambda (symbol value)
+(set-default symbol value)
+(setq notmuch-address-last-harvest 0)
+(setq notmuch-address-completions (clrhash 
notmuch-address-completions))
+(setq notmuch-address-full-harvest-finished nil))
   :group 'notmuch-send
   :group 'notmuch-external)
 
@@ -51,17 +87,6 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
-(defvar notmuch-address-last-harvest 0
-  "Time of last address harvest")
-
-(defvar notmuch-address-completions (make-hash-table :test 'equal)
-  "Hash of email addresses for completion during email composition.
-  This variable is set by calling `notmuch-address-harvest'.")
-
-(defvar notmuch-address-full-harvest-finished nil
-  "t indicates that full completion address harvesting h

[PATCH v2] emacs: address completion, allow sender/recipient and filters

2016-05-13 Thread Mark Walters
This commit lets the user customize the address completion.

The first change controls whether to build the address completion list
based on messages you have sent or you have received (the latter is
much faster).

The second change add a possible filter query to limit the messages
used -- for example, setting this to date:1y..  would limit the
address completions to addresses used in the last year. This speeds up
the address harvest and may also make the search less cluttered as old
addresses may well no longer be valid.
---

I have fixed the bug pointed out by Michal in his review. It seems to
work, but there are a lot of possible configurations,

I also don't like my docstring for the notmuch-address-command
defcustom, so any suggestions gratefully received.

Also, I am not sure whether this is all to much complexity for this
feature.

Best wishes

Mark


 emacs/notmuch-address.el | 104 +++
 emacs/notmuch-company.el |   2 +-
 2 files changed, 71 insertions(+), 35 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index aafbe5f..8b84a4c 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -28,15 +28,50 @@
 ;;
 (declare-function company-manual-begin "company")
 
-(defcustom notmuch-address-command 'internal
-  "The command which generates possible addresses. It must take a
-single argument and output a list of possible matches, one per
-line. The default value of `internal' uses built-in address
-completion."
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
+(defcustom notmuch-address-command '(sent nil)
+  "The command which generates possible addresses.
+
+It can be a (non-nil) list, in which case internal completion is
+used; in this case the first list item 'sent/'received specifies
+whether you match message sent by the user or received by the
+user (note received by is much faster), and the second list item
+should be nil or a filter-string, such as \"date:1y..\" to append
+to the query.
+
+If this variable is nil then address completion is disabled.
+
+If it is a string then that string should be an external program
+which must take a single argument and output a list of possible
+matches, one per line."
   :type '(radio
- (const :tag "Use internal address completion" internal)
+ (list :tag "Use internal address completion"
+   (radio
+:tag "Build list based on messages you have"
+:value sent
+(const :tag "sent" sent)
+(const :tag "received" received))
+   (radio :tag "Filter messages used for completion"
+      (const :tag "Use all messages" nil)
+  (string :tag "Filter query")))
  (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command" "notmuch-addresses"))
+ (string :tag "Use external completion command"))
+  ;; We override set so that we can clear the cache when this changes
+  :set (lambda (symbol value)
+(set-default symbol value)
+(setq notmuch-address-last-harvest 0)
+(setq notmuch-address-completions (clrhash 
notmuch-address-completions))
+(setq notmuch-address-full-harvest-finished nil))
   :group 'notmuch-send
   :group 'notmuch-external)
 
@@ -51,17 +86,6 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
-(defvar notmuch-address-last-harvest 0
-  "Time of last address harvest")
-
-(defvar notmuch-address-completions (make-hash-table :test 'equal)
-  "Hash of email addresses for completion during email composition.
-  This variable is set by calling `notmuch-address-harvest'.")
-
-(defvar notmuch-address-full-harvest-finished nil
-  "t indicates that full completion address harvesting has been
-finished")
-
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -83,7 +107,8 @@ finished")
 
 (defun notmuch-address-setup ()
   (let* ((use-company (and notmuch-address-use-company
-      (eq notmuch-address-command 'internal)
+  notmuch-address-command
+  (listp notmuch-address-command)
   (require

[PATCH 6/6] NEWS: entry for emacs mua address completion

2016-04-24 Thread David Bremner
---
 NEWS | 8 
 1 file changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index 2f91949..303b0a8 100644
--- a/NEWS
+++ b/NEWS
@@ -89,6 +89,14 @@ Handle S/MIME signatures in emacs
   This reduces the amount of interference with non-notmuch uses of
   message-mode.
 
+Address completion improvements
+
+  An external script is no longer needed for address completion; if
+  you previously configured one, customize the variable
+  `notmuch-address-command` to try the internal completion. If
+  `company-mode` is available, notmuch uses it by default for
+  interactive address completion.
+
 Documentation
 -
 
-- 
2.8.0.rc3

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] emacs: address completion, allow sender/recipient and filters

2015-12-28 Thread Michal Sojka
Hi Mark,

I tried this patch. When I set the variable to 'received, first
completion candidates are generated incorrectly. The query looked as
"(to:sojk...@fel.cvut.cz) and (to:prefix*)". It should be "...
(from:prefix*)". This "to:" comes from notmuch-address-options or from
notmuch-company so these should be changes as well.

Other minor comments are below.

Thanks.
-Michal

On Sun, Dec 20 2015, Mark Walters wrote:
> This commit lets the user customize the address completion.
>
> The first change controls whether to build the address completion list
> based on messages you have sent or you have received (the latter is
> much faster).
>
> The second change add a possible filter query to limit the messages
> used -- for example, setting this to date:1y..  would limit the
> address completions to addresses used in the last year. This speeds up
> the address harvest and may also make the search less cluttered as old
> addresses may well no longer be valid.
> ---
>
> There was some discussion on irc about the address completion harvest
> taking a long time. This patch makes is possible to tune this
> behaviour. It may be that this complicates the customize variable too
> much -- but if nothing else its a patch that anyone who experiences
> problems can try.
>
> Best wishes
>
> Mark
>
> emacs/notmuch-address.el | 64 +---
>  1 file changed, 44 insertions(+), 20 deletions(-)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index 49e2402..8942fe4 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -26,15 +26,40 @@
>  ;;
>  (declare-function company-manual-begin "company")
>
> +(defvar notmuch-address-last-harvest 0
> +  "Time of last address harvest")
> +
> +(defvar notmuch-address-completions (make-hash-table :test 'equal)
> +  "Hash of email addresses for completion during email composition.
> +  This variable is set by calling `notmuch-address-harvest'.")
> +
> +(defvar notmuch-address-full-harvest-finished nil
> +  "t indicates that full completion address harvesting has been
> +finished")
> +
>  (defcustom notmuch-address-command 'internal

Default value should be changed to something matching the :type. Perhaps
'(sent nil).

>"The command which generates possible addresses. It must take a
>  single argument and output a list of possible matches, one per
>  line. The default value of `internal' uses built-in address
>  completion."

Doc text can be updated as well.

>:type '(radio
> -   (const :tag "Use internal address completion" internal)
> +   (list :tag "Use internal address completion"
> + (radio
> +  :tag "Build list based on messages you have"
> +  :value sent
> +  (const :tag "sent" sent)
> +  (const :tag "received" received))

I would mention that received is faster here.

> + (radio :tag "Filter messages used for completion"
> +(const :tag "Use all messages" nil)
> +(string :tag "Filter query")))
> (const :tag "Disable address completion" nil)
> -   (string :tag "Use external completion command" "notmuch-addresses"))
> +   (string :tag "Use external completion command"))
> +  ;; We override set so that we can clear the cache when this changes
> +  :set (lambda (symbol value)
> +  (set-default symbol value)
> +  (setq notmuch-address-last-harvest 0)
> +  (setq notmuch-address-completions (clrhash 
> notmuch-address-completions))
> +  (setq notmuch-address-full-harvest-finished nil))
>:group 'notmuch-send
>:group 'notmuch-external)
>
> @@ -49,17 +74,6 @@ to know how address selection is made by default."
>:group 'notmuch-send
>:group 'notmuch-external)
>
> -(defvar notmuch-address-last-harvest 0
> -  "Time of last address harvest")
> -
> -(defvar notmuch-address-completions (make-hash-table :test 'equal)
> -  "Hash of email addresses for completion during email composition.
> -  This variable is set by calling `notmuch-address-harvest'.")
> -
> -(defvar notmuch-address-full-harvest-finished nil
> -  "t indicates that full completion address harvesting has been
> -finished")
> -
>  (defun notmuch-address-selection-function (prompt collection initial-input)
>"Call (`completing-read'
>PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
> @@ -81,7 +95,8 @@ finished")
>
>  (defun not

[PATCH] emacs: address completion, allow sender/recipient and filters

2015-12-20 Thread Mark Walters
This commit lets the user customize the address completion.

The first change controls whether to build the address completion list
based on messages you have sent or you have received (the latter is
much faster).

The second change add a possible filter query to limit the messages
used -- for example, setting this to date:1y..  would limit the
address completions to addresses used in the last year. This speeds up
the address harvest and may also make the search less cluttered as old
addresses may well no longer be valid.
---

There was some discussion on irc about the address completion harvest
taking a long time. This patch makes is possible to tune this
behaviour. It may be that this complicates the customize variable too
much -- but if nothing else its a patch that anyone who experiences
problems can try.

Best wishes

Mark

emacs/notmuch-address.el | 64 +---
 1 file changed, 44 insertions(+), 20 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 49e2402..8942fe4 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -26,15 +26,40 @@
 ;;
 (declare-function company-manual-begin "company")
 
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
 (defcustom notmuch-address-command 'internal
   "The command which generates possible addresses. It must take a
 single argument and output a list of possible matches, one per
 line. The default value of `internal' uses built-in address
 completion."
   :type '(radio
-     (const :tag "Use internal address completion" internal)
+ (list :tag "Use internal address completion"
+   (radio
+:tag "Build list based on messages you have"
+:value sent
+(const :tag "sent" sent)
+(const :tag "received" received))
+   (radio :tag "Filter messages used for completion"
+  (const :tag "Use all messages" nil)
+  (string :tag "Filter query")))
  (const :tag "Disable address completion" nil)
- (string :tag "Use external completion command" "notmuch-addresses"))
+ (string :tag "Use external completion command"))
+  ;; We override set so that we can clear the cache when this changes
+  :set (lambda (symbol value)
+(set-default symbol value)
+(setq notmuch-address-last-harvest 0)
+(setq notmuch-address-completions (clrhash 
notmuch-address-completions))
+(setq notmuch-address-full-harvest-finished nil))
   :group 'notmuch-send
   :group 'notmuch-external)
 
@@ -49,17 +74,6 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
-(defvar notmuch-address-last-harvest 0
-  "Time of last address harvest")
-
-(defvar notmuch-address-completions (make-hash-table :test 'equal)
-  "Hash of email addresses for completion during email composition.
-  This variable is set by calling `notmuch-address-harvest'.")
-
-(defvar notmuch-address-full-harvest-finished nil
-  "t indicates that full completion address harvesting has been
-finished")
-
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -81,7 +95,8 @@ finished")
 
 (defun notmuch-address-setup ()
   (let* ((use-company (and notmuch-address-use-company
-  (eq notmuch-address-command 'internal)
+  notmuch-address-command
+  (listp notmuch-address-command)
   (require 'company nil t)))
 (pair (cons notmuch-address-completion-headers-regexp
 (if use-company
@@ -109,7 +124,7 @@ The candidates are taken from 
`notmuch-address-completions'."
 elisp-based implementation or older implementation requiring
 external commands."
   (cond
-   ((eq notmuch-address-command 'internal)
+   ((and notmuch-address-command (listp notmuch-address-command))
 (when (not notmuch-address-full-harvest-finished)
   ;; First, run quick synchronous harvest based on what the user
   ;; entered so far
@@ -198,12 +213,21 @@ addresses from those messages and stores them in
 time so the address collection runs asynchronously unless
 SYNCHRONOUS is t. In case of asynchronous execution, CALLBACK is
 c

[PATCH v8 3/3] Emacs: Add address completion based on company-mode

2015-10-26 Thread Michal Sojka
When company-mode is available (Emacs >= 24), address completion
candidates are shown in a nice popup box. This is triggered either by
pressing TAB or by waiting a while during typing an address. The
completion is based entirely on the asynchronous address harvesting
from notmuch-address.el so the GUI is theoretically not blocked for
long time.

The completion works similarly as the TAB-initiated completion from
notmuch-address.el, i.e. quick harvest based on user input is executed
first and only after full harvesting is finished, in-memory cached data
is used.

[Improved by David Bremner]
---
 emacs/Makefile.local |  1 +
 emacs/notmuch-address.el | 18 --
 emacs/notmuch-company.el | 86 
 3 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 emacs/notmuch-company.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 1109cfa..4c06c52 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -20,6 +20,7 @@ emacs_sources := \
$(dir)/notmuch-print.el \
$(dir)/notmuch-version.el \
$(dir)/notmuch-jump.el \
+   $(dir)/notmuch-company.el
 
 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
 $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 498ef8a..49e2402 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -22,7 +22,9 @@
 (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
+(require 'notmuch-company)
 ;;
+(declare-function company-manual-begin "company")
 
 (defcustom notmuch-address-command 'internal
   "The command which generates possible addresses. It must take a
@@ -72,9 +74,21 @@ finished")
 (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
+(defcustom notmuch-address-use-company t
+  "If available, use company mode for address completion"
+  :type 'boolean
+  :group 'notmuch-send)
+
 (defun notmuch-address-setup ()
-  (let ((pair (cons notmuch-address-completion-headers-regexp
-   #'notmuch-address-expand-name)))
+  (let* ((use-company (and notmuch-address-use-company
+  (eq notmuch-address-command 'internal)
+  (require 'company nil t)))
+    (pair (cons notmuch-address-completion-headers-regexp
+(if use-company
+#'company-manual-begin
+  #'notmuch-address-expand-name
+  (when use-company
+   (notmuch-company-setup))
   (unless (memq pair message-completion-alist)
(setq message-completion-alist
  (push pair message-completion-alist)
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
new file mode 100644
index 000..add3161
--- /dev/null
+++ b/emacs/notmuch-company.el
@@ -0,0 +1,86 @@
+;; notmuch-company.el --- Mail address completion for notmuch via company-mode 
 -*- lexical-binding: t -*-
+
+;; Authors: Trevor Jim <t...@mac.com>
+;; Michal Sojka <sojk...@fel.cvut.cz>
+;;
+;; Keywords: mail, completion
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; To enable this, install company mode (https://company-mode.github.io/)
+;;
+;; NB company-minimum-prefix-length defaults to 3 so you don't get
+;; completion unless you type 3 characters
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+
+(defvar notmuch-company-last-prefix nil)
+(make-variable-buffer-local 'notmuch-company-last-prefix)
+(declare-function company-begin-backend "company")
+(declare-function company-grab "company")
+(declare-function company-mode "company")
+(declare-function company-manual-begin "company")
+(defvar company-backends)
+
+(declare-function notmuch-address-harvest "notmuch-address")
+(declare-function notmuch-address-harvest-trigger "notmuch-address")
+(declare-function notmuch-address-matching "notmuch-address")
+(defvar notmuch-address-full-harvest-finished)
+(defvar notmuch-address-completion-headers-regexp)
+
+;;;###autoload
+(defun notmuch-company-setup ()
+  (company-mode)
+  (make-local-variable 'company-backends)
+  (setq company-backends '(notmu

[PATCH v8 2/3] Emacs: Add address completion mechanism implemented in elisp

2015-10-26 Thread Michal Sojka
Currently, notmuch has an address completion mechanism that requires
external command to provide completion candidates. This commit adds a
completion mechanism inspired by https://github.com/tjim/nevermore,
which is implemented in Emacs lisp only.

The preexisting address completion mechanism, activated by pressing
TAB on To/Cc lines, is extended to use the new mechanism when
notmuch-address-command to 'internal, which is the new default.

The core of the new mechanism is the function notmuch-address-harvest,
which collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable. The address
harvesting can run either synchronously (same as with the previous
mechanism) or asynchronously. When the user presses TAB for the first
time, synchronous harvesting limited to user entered text is performed.
If the entered text is reasonably long, this operation is relatively
fast. Then, asynchronous harvesting over the full database is triggered.
This operation may take long time (minutes on rotating disk). After it
finishes, no harvesting is normally performed again and subsequent
completion requests use the harvested data cached in memory. Completion
cache is updated after 24 hours.

Note that this commit restores (different) completion functionality for
users when the user used external command named "notmuch-addresses",
i.e. the old default.  The result will be that the user will use
the new mechanism instead of this command. I believe that many users may
not even recognize this because the new mechanism works the same as
http://commonmeasure.org/~jkr/git/notmuch_addresses.git and perhaps also
as other commands suggested at
http://notmuchmail.org/emacstips/#address_completion.

[This feature was significantly improved by David Bremner and Mark Walters]
---
 emacs/notmuch-address.el | 192 ++-
 emacs/notmuch-lib.el |   3 +
 2 files changed, 159 insertions(+), 36 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index e2af879..498ef8a 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -20,14 +20,17 @@
 ;; Authors: David Edmondson <d...@dme.org>
 
 (require 'message)
-
+(require 'notmuch-parser)
+(require 'notmuch-lib)
 ;;
 
-(defcustom notmuch-address-command nil
+(defcustom notmuch-address-command 'internal
   "The command which generates possible addresses. It must take a
 single argument and output a list of possible matches, one per
-line. The default value of nil disables address completion."
+line. The default value of `internal' uses built-in address
+completion."
   :type '(radio
+ (const :tag "Use internal address completion" internal)
  (const :tag "Disable address completion" nil)
  (string :tag "Use external completion command" "notmuch-addresses"))
   :group 'notmuch-send
@@ -44,15 +47,25 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
   (completing-read
prompt collection nil nil initial-input 'notmuch-address-history))
 
-(defvar notmuch-address-message-alist-member
-  
'("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
- . notmuch-address-expand-name))
+(defvar notmuch-address-completion-headers-regexp
+  
"^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):")
 
 (defvar notmuch-address-history nil)
 
@@ -60,39 +73,67 @@ to know how address selection is made by default."
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (unless (memq notmuch-address-message-alist-member message-completion-alist)
-    (setq message-completion-alist
- (push notmuch-address-message-alist-member 
message-completion-alist
+  (let ((pair (cons notmuch-address-completion-headers-regexp
+   #'notmuch-address-expand-name)))
+  (unless (memq pair message-completion-alist)
+   (setq message-completion-alist
+ (push pair message-completion-alist)
+
+(defun notmuch-address-matching (substring)
+  "Returns a list of completion candidates matching SUBSTRING

[PATCH] address completion tweaks

2015-10-25 Thread Mark Walters
If the user has company installed and notmuch is configured to use it,
then use it for all the completions. In particular, pressing tab now
forces company to run immediately.

In addition this patch fixes a semi-bug where address completion was
used for more headers than company mode was. With the change above
this became important. Thus make company mode work for all headers
that address completion does.
---

I think this is an improvement: without pressing tab quickly brings up
the normal mini-buffer completion mode, but waiting a second means
company has started and then tab doesn't bring up the mini-buffer.

The change in notmuch-mua is just so that company-setup runs before we
setup the message-completion-alist.

Best wishes

Mark



emacs/notmuch-address.el |  7 ---
 emacs/notmuch-company.el |  5 +++--
 emacs/notmuch-mua.el | 10 +-
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 228135e..0a73ddf 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -64,9 +64,11 @@ (defun notmuch-address-selection-function (prompt collection 
initial-input)
   (completing-read
prompt collection nil nil initial-input 'notmuch-address-history))
 
+(defvar notmuch-address-completion-headers-regexp
+  
"^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):")
+
 (defvar notmuch-address-message-alist-member
-  
'("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
- . notmuch-address-expand-name))
+  (cons notmuch-address-completion-headers-regexp 
'notmuch-address-expand-name))
 
 (defvar notmuch-address-history nil)
 
@@ -221,7 +223,6 @@ (defun notmuch-address-harvest-trigger ()
 (if (string= event "finished\n")
 (setq 
notmuch-address-full-harvest-finished t)
   (setq notmuch-address-last-harvest 0)))
-
 ;;
 
 (provide 'notmuch-address)
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
index 9e57914..3157ed7 100644
--- a/emacs/notmuch-company.el
+++ b/emacs/notmuch-company.el
@@ -41,6 +41,8 @@ (defvar company-backends)
 ;;;###autoload
 (defun notmuch-company-setup ()
   (company-mode)
+  (setq notmuch-address-message-alist-member
+   (cons notmuch-address-completion-headers-regexp 'company-manual-begin))
   (make-local-variable 'company-backends)
   (setq company-backends '(notmuch-company)))
 
@@ -54,7 +56,7 @@ (defun notmuch-company (command  arg  _ignore)
 (case command
   (interactive (company-begin-backend 'notmuch-company))
   (prefix (and (derived-mode-p 'message-mode)
-  (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
+      (looking-back (concat 
notmuch-address-completion-headers-regexp ".*")
 (line-beginning-position))
   (setq notmuch-company-last-prefix (company-grab "[:,][ 
\t]*\\(.*\\)" 1 (point-at-bol)
   (candidates (cond
@@ -77,5 +79,4 @@ (defun notmuch-company (command  arg  _ignore)
   0))
   (no-cache t
 
-
 (provide 'notmuch-company)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 63fc8db..8cbf38c 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -276,13 +276,13 @@ (defcustom notmuch-message-use-company t
 (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
   "Notmuch message composition mode. Mostly like `message-mode'"
   (when notmuch-address-command
+(when (and notmuch-message-use-company
+  (eq notmuch-address-command 'internal)
+  (require 'company nil t))
+  (notmuch-company-setup))
 (unless (memq notmuch-address-message-alist-member 
message-completion-alist)
   (setq message-completion-alist
-   (push notmuch-address-message-alist-member 
message-completion-alist
-  (when (and notmuch-message-use-company
-(eq notmuch-address-command 'internal)
-(require 'company nil t))
-(notmuch-company-setup)))
+   (push notmuch-address-message-alist-member 
message-completion-alist)
 
 (define-key notmuch-message-mode-map (kbd "C-c C-c") 
#'notmuch-mua-send-and-exit)
 (define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Patch v7 2/3] Emacs: Add address completion mechanism implemented in elisp

2015-10-25 Thread Mark Walters
On Sun, 25 Oct 2015, David Bremner <da...@tethera.net> wrote:
> From: Michal Sojka <sojk...@fel.cvut.cz>
>
> Currently, notmuch has an address completion mechanism that requires
> external command to provide completion candidates. This patch adds a
> completion mechanism inspired by https://github.com/tjim/nevermore,
> which is implemented in Emacs lisp only.
>
> The preexisting address completion mechanism, activated by pressing TAB
> on To/Cc lines, is extended to use the new mechanism when no external
> command is configured, i.e. when notmuch-address-command to nil, which
> is the new default.
>
> The core of the new mechanism is the function notmuch-address-harvest,
> which collects the completion candidates from the notmuch database and
> stores them in notmuch-address-completions variable. The address
> harvesting can run either synchronously (same as with the previous
> mechanism) or asynchronously. When the user presses TAB for the first
> time, synchronous harvesting limited to user entered text is performed.
> If the entered text is reasonably long, this operation is relatively
> fast. Then, asynchronous harvesting over the full database is triggered.
> This operation may take long time (minutes on rotating disk). After it
> finishes, no harvesting is normally performed again and subsequent
> completion requests use the harvested data cached in memory. Completion
> cache is updated after 24 hours.
>
> Note that this commit restores (different) completion functionality for
> users when the user used external command named "notmuch-addresses",
> i.e. the old default.  The result will be that the user will use
> the new mechanism instead of this command. I believe that many users may
> not even recognize this because the new mechanism works the same as
> http://commonmeasure.org/~jkr/git/notmuch_addresses.git and perhaps also
> as other commands suggested at
> http://notmuchmail.org/emacstips/#address_completion.
> ---
>  emacs/notmuch-address.el | 192 
> ++-
>  emacs/notmuch-lib.el |   3 +
>  2 files changed, 159 insertions(+), 36 deletions(-)
>
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index e2af879..aa6228d 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -20,14 +20,17 @@
>  ;; Authors: David Edmondson <d...@dme.org>
>  
>  (require 'message)
> -
> +(require 'notmuch-parser)
> +(require 'notmuch-lib)
>  ;;
>  
> -(defcustom notmuch-address-command nil
> +(defcustom notmuch-address-command 'internal
>    "The command which generates possible addresses. It must take a
>  single argument and output a list of possible matches, one per
> -line. The default value of nil disables address completion."
> +line. The default value of `internal' uses built-in address
> +completion."
>:type '(radio
> +   (const :tag "Use internal address completion" internal)
> (const :tag "Disable address completion" nil)
> (string :tag "Use external completion command" "notmuch-addresses"))
>:group 'notmuch-send
> @@ -44,15 +47,25 @@ to know how address selection is made by default."
>:group 'notmuch-send
>:group 'notmuch-external)
>  
> +(defvar notmuch-address-last-harvest 0
> +  "Time of last address harvest")
> +
> +(defvar notmuch-address-completions (make-hash-table :test 'equal)
> +  "Hash of email addresses for completion during email composition.
> +  This variable is set by calling `notmuch-address-harvest'.")
> +
> +(defvar notmuch-address-full-harvest-finished nil
> +  "t indicates that full completion address harvesting has been
> +finished")
> +
>  (defun notmuch-address-selection-function (prompt collection initial-input)
>"Call (`completing-read'
>PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
>(completing-read
> prompt collection nil nil initial-input 'notmuch-address-history))
>  
> -(defvar notmuch-address-message-alist-member
> -  
> '("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
> -   . notmuch-address-expand-name))
> +(defvar notmuch-address-completion-headers-regexp
> +  
> "^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):")
>  
>  (defvar notmuch-address-history nil)
>  
> @@ -60,39 +73,67 @@ to know how address selection is made by default."
>(message "calling notmuch-address-message-insinuate is no longer needed"))
>  
>  (defun notmuch-address-setup ()
> -  

Re: [Patch v7 3/3] Emacs: Add address completion based on company-mode

2015-10-25 Thread Mark Walters

On Sun, 25 Oct 2015, David Bremner <da...@tethera.net> wrote:
> From: Michal Sojka <sojk...@fel.cvut.cz>
>
> With this patch, address completion candidates are shown automatically
> after short typing delay in a nice popup box. This requires company-mode
> to be installed and it works only on Emacs >= 24. The completion is
> based entirely on the asynchronous address harvesting from
> notmuch-address.el so the GUI is theoretically not blocked for long
> time.
>
> The completion works similarly as the TAB-initiated completion from
> notmuch-address.el, i.e. quick harvest based on user input is executed
> first and only after full harvesting is finished, in-memory cached data
> is used.
> ---

This series looks good to me. There are a couple of very small nits that
might be worth fixing (on the level of typos/whitespace see below and a
reply to patch 2). But +1 from me for this version.


Best wishes

Mark

>  emacs/Makefile.local |  1 +
>  emacs/notmuch-address.el | 18 --
>  emacs/notmuch-company.el | 86 
> 
>  emacs/notmuch-mua.el |  2 +-
>  4 files changed, 104 insertions(+), 3 deletions(-)
>  create mode 100644 emacs/notmuch-company.el
>
> diff --git a/emacs/Makefile.local b/emacs/Makefile.local
> index 1109cfa..4c06c52 100644
> --- a/emacs/Makefile.local
> +++ b/emacs/Makefile.local
> @@ -20,6 +20,7 @@ emacs_sources := \
>   $(dir)/notmuch-print.el \
>   $(dir)/notmuch-version.el \
>   $(dir)/notmuch-jump.el \
> + $(dir)/notmuch-company.el
>  
>  $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
>  $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
> diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
> index aa6228d..5456d5c 100644
> --- a/emacs/notmuch-address.el
> +++ b/emacs/notmuch-address.el
> @@ -22,7 +22,9 @@
>  (require 'message)
>  (require 'notmuch-parser)
>  (require 'notmuch-lib)
> +(require 'notmuch-company)
>  ;;
> +(declare-function company-manual-begin "company")
>  
>  (defcustom notmuch-address-command 'internal
>"The command which generates possible addresses. It must take a
> @@ -72,9 +74,21 @@ finished")
>  (defun notmuch-address-message-insinuate ()
>(message "calling notmuch-address-message-insinuate is no longer needed"))
>  
> +(defcustom notmuch-address-use-company t
> +  "If available, use company mode for address completion"
> +  :type 'boolean
> +  :group 'notmuch-send)
> +
>  (defun notmuch-address-setup ()
> -  (let ((pair (cons notmuch-address-completion-headers-regexp
> - #'notmuch-address-expand-name)))
> +  (let* ((use-company (and notmuch-address-use-company
> +(eq notmuch-address-command 'internal)
> +(require 'company nil t)))
> +  (pair (cons notmuch-address-completion-headers-regexp
> +  (if use-company
> +  #'company-manual-begin
> +#'notmuch-address-expand-name
> +  (when use-company
> + (notmuch-company-setup))
>(unless (memq pair message-completion-alist)
>   (setq message-completion-alist
>     (push pair message-completion-alist)
> diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
> new file mode 100644
> index 000..49d1d81
> --- /dev/null
> +++ b/emacs/notmuch-company.el
> @@ -0,0 +1,86 @@
> +;; notmuch-company.el --- Mail address completion for notmuch via 
> company-mode  -*- lexical-binding: t -*-
> +
> +;; Authors: Trevor Jim <t...@mac.com>
> +;;   Michal Sojka <sojk...@fel.cvut.cz>
> +;;
> +;; Keywords: mail, completion
> +
> +;; This program is free software; you can redistribute it and/or modify
> +;; it under the terms of the GNU General Public License as published by
> +;; the Free Software Foundation, either version 3 of the License, or
> +;; (at your option) any later version.
> +
> +;; This program is distributed in the hope that it will be useful,
> +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;; GNU General Public License for more details.
> +
> +;; You should have received a copy of the GNU General Public License
> +;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +;;; Commentary:
> +
> +;; To enable this, install company mode (https://company-mode.github.io/)
> +;;
> +;; NB company-minimum-prefix-length defaults to 3 so you don't get
> +;; completion unless you type 3 characters
> +
> +;;; Code:
> +
> +(eval-whe

[Patch v7 2/3] Emacs: Add address completion mechanism implemented in elisp

2015-10-25 Thread David Bremner
From: Michal Sojka <sojk...@fel.cvut.cz>

Currently, notmuch has an address completion mechanism that requires
external command to provide completion candidates. This patch adds a
completion mechanism inspired by https://github.com/tjim/nevermore,
which is implemented in Emacs lisp only.

The preexisting address completion mechanism, activated by pressing TAB
on To/Cc lines, is extended to use the new mechanism when no external
command is configured, i.e. when notmuch-address-command to nil, which
is the new default.

The core of the new mechanism is the function notmuch-address-harvest,
which collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable. The address
harvesting can run either synchronously (same as with the previous
mechanism) or asynchronously. When the user presses TAB for the first
time, synchronous harvesting limited to user entered text is performed.
If the entered text is reasonably long, this operation is relatively
fast. Then, asynchronous harvesting over the full database is triggered.
This operation may take long time (minutes on rotating disk). After it
finishes, no harvesting is normally performed again and subsequent
completion requests use the harvested data cached in memory. Completion
cache is updated after 24 hours.

Note that this commit restores (different) completion functionality for
users when the user used external command named "notmuch-addresses",
i.e. the old default.  The result will be that the user will use
the new mechanism instead of this command. I believe that many users may
not even recognize this because the new mechanism works the same as
http://commonmeasure.org/~jkr/git/notmuch_addresses.git and perhaps also
as other commands suggested at
http://notmuchmail.org/emacstips/#address_completion.
---
 emacs/notmuch-address.el | 192 ++-
 emacs/notmuch-lib.el |   3 +
 2 files changed, 159 insertions(+), 36 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index e2af879..aa6228d 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -20,14 +20,17 @@
 ;; Authors: David Edmondson <d...@dme.org>
 
 (require 'message)
-
+(require 'notmuch-parser)
+(require 'notmuch-lib)
 ;;
 
-(defcustom notmuch-address-command nil
+(defcustom notmuch-address-command 'internal
   "The command which generates possible addresses. It must take a
 single argument and output a list of possible matches, one per
-line. The default value of nil disables address completion."
+line. The default value of `internal' uses built-in address
+completion."
   :type '(radio
+     (const :tag "Use internal address completion" internal)
  (const :tag "Disable address completion" nil)
  (string :tag "Use external completion command" "notmuch-addresses"))
   :group 'notmuch-send
@@ -44,15 +47,25 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
   (completing-read
prompt collection nil nil initial-input 'notmuch-address-history))
 
-(defvar notmuch-address-message-alist-member
-  
'("^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
- . notmuch-address-expand-name))
+(defvar notmuch-address-completion-headers-regexp
+  
"^\\(Resent-\\)?\\(To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):")
 
 (defvar notmuch-address-history nil)
 
@@ -60,39 +73,67 @@ to know how address selection is made by default."
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
 (defun notmuch-address-setup ()
-  (unless (memq notmuch-address-message-alist-member message-completion-alist)
-(setq message-completion-alist
- (push notmuch-address-message-alist-member 
message-completion-alist
+  (let ((pair (cons notmuch-address-completion-headers-regexp
+   #'notmuch-address-expand-name)))
+  (unless (memq pair message-completion-alist)
+   (setq message-completion-alist
+ (push pair message-completion-alist)
+
+(defun notmuch-address-matching (substring)
+  "Returns a list of completion candidates matching SUB

[Patch v7 3/3] Emacs: Add address completion based on company-mode

2015-10-25 Thread David Bremner
From: Michal Sojka <sojk...@fel.cvut.cz>

With this patch, address completion candidates are shown automatically
after short typing delay in a nice popup box. This requires company-mode
to be installed and it works only on Emacs >= 24. The completion is
based entirely on the asynchronous address harvesting from
notmuch-address.el so the GUI is theoretically not blocked for long
time.

The completion works similarly as the TAB-initiated completion from
notmuch-address.el, i.e. quick harvest based on user input is executed
first and only after full harvesting is finished, in-memory cached data
is used.
---
 emacs/Makefile.local |  1 +
 emacs/notmuch-address.el | 18 --
 emacs/notmuch-company.el | 86 
 emacs/notmuch-mua.el |  2 +-
 4 files changed, 104 insertions(+), 3 deletions(-)
 create mode 100644 emacs/notmuch-company.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 1109cfa..4c06c52 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -20,6 +20,7 @@ emacs_sources := \
$(dir)/notmuch-print.el \
$(dir)/notmuch-version.el \
$(dir)/notmuch-jump.el \
+   $(dir)/notmuch-company.el
 
 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
 $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index aa6228d..5456d5c 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -22,7 +22,9 @@
 (require 'message)
 (require 'notmuch-parser)
 (require 'notmuch-lib)
+(require 'notmuch-company)
 ;;
+(declare-function company-manual-begin "company")
 
 (defcustom notmuch-address-command 'internal
   "The command which generates possible addresses. It must take a
@@ -72,9 +74,21 @@ finished")
 (defun notmuch-address-message-insinuate ()
   (message "calling notmuch-address-message-insinuate is no longer needed"))
 
+(defcustom notmuch-address-use-company t
+  "If available, use company mode for address completion"
+  :type 'boolean
+  :group 'notmuch-send)
+
 (defun notmuch-address-setup ()
-  (let ((pair (cons notmuch-address-completion-headers-regexp
-   #'notmuch-address-expand-name)))
+  (let* ((use-company (and notmuch-address-use-company
+  (eq notmuch-address-command 'internal)
+  (require 'company nil t)))
+(pair (cons notmuch-address-completion-headers-regexp
+(if use-company
+#'company-manual-begin
+  #'notmuch-address-expand-name
+  (when use-company
+   (notmuch-company-setup))
   (unless (memq pair message-completion-alist)
(setq message-completion-alist
  (push pair message-completion-alist)
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
new file mode 100644
index 000..49d1d81
--- /dev/null
+++ b/emacs/notmuch-company.el
@@ -0,0 +1,86 @@
+;; notmuch-company.el --- Mail address completion for notmuch via company-mode 
 -*- lexical-binding: t -*-
+
+;; Authors: Trevor Jim <t...@mac.com>
+;; Michal Sojka <sojk...@fel.cvut.cz>
+;;
+;; Keywords: mail, completion
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; To enable this, install company mode (https://company-mode.github.io/)
+;;
+;; NB company-minimum-prefix-length defaults to 3 so you don't get
+;; completion unless you type 3 characters
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+
+(defvar notmuch-company-last-prefix nil)
+(make-variable-buffer-local 'notmuch-company-last-prefix)
+(declare-function company-begin-backend "company")
+(declare-function company-grab "company")
+(declare-function company-mode "company")
+(declare-function company-manual-begin "company")
+(defvar company-backends)
+
+(declare-function notmuch-address-harvest "notmuch-address")
+(declare-function notmuch-address-harvest-trigger "notmuch-address")
+(declare-function notmuch-address-matching "notmuch-address")
+(defvar notmuch-address-full-harvest-finished)
+(defvar notmuch-address-completion-headers-regexp)
+
+;;;###autoload
+(defun notmuch-company-setup ()
+  (company-mode)
+  (make-local-va

[PATCH 2/3] Emacs: Add address completion mechanism implemented in elisp

2015-10-24 Thread David Bremner
From: Michal Sojka <sojk...@fel.cvut.cz>

Currently, notmuch has an address completion mechanism that requires
external command to provide completion candidates. This patch adds a
completion mechanism inspired by https://github.com/tjim/nevermore,
which is implemented in Emacs lisp only.

The preexisting address completion mechanism, activated by pressing TAB
on To/Cc lines, is extended to use the new mechanism when no external
command is configured, i.e. when notmuch-address-command to nil, which
is the new default.

The core of the new mechanism is the function notmuch-address-harvest,
which collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable. The address
harvesting can run either synchronously (same as with the previous
mechanism) or asynchronously. When the user presses TAB for the first
time, synchronous harvesting limited to user entered text is performed.
If the entered text is reasonably long, this operation is relatively
fast. Then, asynchronous harvesting over the full database is triggered.
This operation may take long time (minutes on rotating disk). After it
finishes, no harvesting is normally performed again and subsequent
completion requests use the harvested data cached in memory. Completion
cache is updated after 24 hours.

Note that this commit restores (different) completion functionality for
users when the user used external command named "notmuch-addresses",
i.e. the old default.  The result will be that the user will use
the new mechanism instead of this command. I believe that many users may
not even recognize this because the new mechanism works the same as
http://commonmeasure.org/~jkr/git/notmuch_addresses.git and perhaps also
as other commands suggested at
http://notmuchmail.org/emacstips/#address_completion.
---
 emacs/notmuch-address.el | 108 +--
 emacs/notmuch-lib.el |   3 ++
 2 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 39200ef..2a748ec 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -20,14 +20,17 @@
 ;; Authors: David Edmondson <d...@dme.org>
 
 (require 'message)
-
+(require 'notmuch-parser)
+(require 'notmuch-lib)
 ;;
 
-(defcustom notmuch-address-command nil
+(defcustom notmuch-address-command 'internal
   "The command which generates possible addresses. It must take a
 single argument and output a list of possible matches, one per
-line. The default value of nil disables address completion."
+line. The default value of `internal' uses built-in address
+completion."
   :type '(radio
+     (const :tag "Use internal address completion" internal)
  (const :tag "Disable address completion" nil)
  (string :tag "Use external completion command" "notmuch-addresses"))
   :group 'notmuch-send
@@ -44,6 +47,17 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -56,8 +70,32 @@ to know how address selection is made by default."
 
 (defvar notmuch-address-history nil)
 
+(defun notmuch-address-matching (substring)
+  "Returns a list of completion candidates matching SUBSTRING.
+The candidates are taked form `notmuch-address-completions'."
+  (let ((candidates)
+   (re (regexp-quote substring)))
+(maphash (lambda (key val)
+  (when (string-match re key)
+(push key candidates)))
+notmuch-address-completions)
+candidates))
+
 (defun notmuch-address-options (original)
-  (process-lines notmuch-address-command original))
+  "Returns a list of completion candidates. Uses either
+elisp-based implementation or older implementation requiring
+external commands."
+  (cond
+   ((eq notmuch-address-command 'internal)
+(when (not notmuch-address-full-harvest-finished)
+  ;; First, run quick synchronous harvest based on what the user
+  ;; entered so far
+  (notmuch-address-harvest (format "to:%s*" original) t))
+(prog1 (notmuch-address-matching original)
+  ;; Then (re)start potentially long-running full asynchronous harvesting
+  (notmuch-address-harvest-trigger)))
+   (t
+(process-lines not

[PATCH 3/3] Emacs: Add address completion based on company-mode

2015-10-24 Thread David Bremner
From: Michal Sojka <sojk...@fel.cvut.cz>

With this patch, address completion candidates are shown automatically
after short typing delay in a nice popup box. This requires company-mode
to be installed and it works only on Emacs >= 24. The completion is
based entirely on the asynchronous address harvesting from
notmuch-address.el so the GUI is theoretically not blocked for long
time.

The completion works similarly as the TAB-initiated completion from
notmuch-address.el, i.e. quick harvest based on user input is executed
first and only after full harvesting is finished, in-memory cached data
is used.
---
 emacs/Makefile.local |  1 +
 emacs/notmuch-company.el | 73 
 emacs/notmuch-mua.el | 13 -
 3 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 emacs/notmuch-company.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 1109cfa..4c06c52 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -20,6 +20,7 @@ emacs_sources := \
$(dir)/notmuch-print.el \
$(dir)/notmuch-version.el \
$(dir)/notmuch-jump.el \
+   $(dir)/notmuch-company.el
 
 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
 $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
new file mode 100644
index 000..03c492f
--- /dev/null
+++ b/emacs/notmuch-company.el
@@ -0,0 +1,73 @@
+;; notmuch-company.el --- Mail address completion for notmuch via company-mode 
 -*- lexical-binding: t -*-
+
+
+;; Authors: Trevor Jim <t...@mac.com>
+;; Michal Sojka <sojk...@fel.cvut.cz>
+;;
+;; Keywords: mail, completion
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; To enable this, install company mode (https://company-mode.github.io/)
+;; and customize notmuch-message-use-company
+;;
+;; NB company-minimum-prefix-length defaults to 3 so you don't get
+;; completion unless you type 3 characters
+
+;;; Code:
+
+(require 'notmuch-address)
+(require 'cl-lib)
+
+(defvar-local notmuch-company-last-prefix nil)
+(declare-function company-begin-backend "company")
+(declare-function company-grab "company")
+
+;;;###autoload
+(defun notmuch-company (command  arg  _ignore)
+  "`company-mode' completion back-end for `notmuch'."
+  (interactive (list 'interactive))
+  (require 'company)
+  (let ((case-fold-search t)
+   (completion-ignore-case t))
+(cl-case command
+  (interactive (company-begin-backend 'notmuch-company))
+  (prefix (and (derived-mode-p 'message-mode)
+  (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
+(line-beginning-position))
+  (setq notmuch-company-last-prefix (company-grab "[:,][ 
\t]*\\(.*\\)" 1 (point-at-bol)
+  (candidates (cond
+  (notmuch-address-full-harvest-finished
+   ;; Update harvested addressed from time to time
+   (notmuch-address-harvest-trigger)
+   (notmuch-address-matching arg))
+  (t
+   (cons :async
+ (lambda (callback)
+   ;; First run quick asynchronous harvest based on 
what the user entered so far
+   (notmuch-address-harvest
+(format "to:%s*" arg) nil
+(lambda (_proc _event)
+  (funcall callback (notmuch-address-matching arg))
+  ;; Then (re)start potentially long-running full 
asynchronous harvesting
+  (notmuch-address-harvest-trigger
+  (match (if (string-match notmuch-company-last-prefix arg)
+(match-end 0)
+  0))
+  (no-cache t
+
+
+(provide 'notmuch-company)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 6cc9656..c90381d 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -25,6 +25,7 @@
 
 (require 'notmuch-lib)
 (require 'notmuch-address)
+(require 'notmuch-company)
 
 (eval-when-compile (require 'cl))
 
@@ -268,12 +269,22 @@ Note that these functions use `mail-citation-hook' if 
that is non-nil."
   (message-goto-body)
   (s

Re: [PATCH 3/3] Emacs: Add address completion based on company-mode

2015-10-24 Thread Mark Walters
On Sat, 24 Oct 2015, David Bremner <da...@tethera.net> wrote:
> From: Michal Sojka <sojk...@fel.cvut.cz>
>
> With this patch, address completion candidates are shown automatically
> after short typing delay in a nice popup box. This requires company-mode
> to be installed and it works only on Emacs >= 24. The completion is
> based entirely on the asynchronous address harvesting from
> notmuch-address.el so the GUI is theoretically not blocked for long
> time.
>
> The completion works similarly as the TAB-initiated completion from
> notmuch-address.el, i.e. quick harvest based on user input is executed
> first and only after full harvesting is finished, in-memory cached data
> is used.
> ---
>  emacs/Makefile.local |  1 +
>  emacs/notmuch-company.el | 73 
> 
>  emacs/notmuch-mua.el | 13 -
>  3 files changed, 86 insertions(+), 1 deletion(-)
>  create mode 100644 emacs/notmuch-company.el
>
> diff --git a/emacs/Makefile.local b/emacs/Makefile.local
> index 1109cfa..4c06c52 100644
> --- a/emacs/Makefile.local
> +++ b/emacs/Makefile.local
> @@ -20,6 +20,7 @@ emacs_sources := \
>   $(dir)/notmuch-print.el \
>   $(dir)/notmuch-version.el \
>   $(dir)/notmuch-jump.el \
> + $(dir)/notmuch-company.el
>  
>  $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
>  $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
> diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
> new file mode 100644
> index 0000000..03c492f
> --- /dev/null
> +++ b/emacs/notmuch-company.el
> @@ -0,0 +1,73 @@
> +;; notmuch-company.el --- Mail address completion for notmuch via 
> company-mode  -*- lexical-binding: t -*-
> +
> +
> +;; Authors: Trevor Jim <t...@mac.com>
> +;;   Michal Sojka <sojk...@fel.cvut.cz>
> +;;
> +;; Keywords: mail, completion
> +
> +;; This program is free software; you can redistribute it and/or modify
> +;; it under the terms of the GNU General Public License as published by
> +;; the Free Software Foundation, either version 3 of the License, or
> +;; (at your option) any later version.
> +
> +;; This program is distributed in the hope that it will be useful,
> +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;; GNU General Public License for more details.
> +
> +;; You should have received a copy of the GNU General Public License
> +;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +;;; Commentary:
> +
> +;; To enable this, install company mode (https://company-mode.github.io/)
> +;; and customize notmuch-message-use-company
> +;;
> +;; NB company-minimum-prefix-length defaults to 3 so you don't get
> +;; completion unless you type 3 characters
> +
> +;;; Code:
> +
> +(require 'notmuch-address)
> +(require 'cl-lib)
> +
> +(defvar-local notmuch-company-last-prefix nil)
> +(declare-function company-begin-backend "company")
> +(declare-function company-grab "company")
> +
> +;;;###autoload
> +(defun notmuch-company (command  arg  _ignore)
> +  "`company-mode' completion back-end for `notmuch'."
> +  (interactive (list 'interactive))
> +  (require 'company)
> +  (let ((case-fold-search t)
> + (completion-ignore-case t))
> +(cl-case command
> +  (interactive (company-begin-backend 'notmuch-company))
> +  (prefix (and (derived-mode-p 'message-mode)
> +(looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
> +  (line-beginning-position))
> +(setq notmuch-company-last-prefix (company-grab "[:,][ 
> \t]*\\(.*\\)" 1 (point-at-bol)
> +  (candidates (cond
> +(notmuch-address-full-harvest-finished
> + ;; Update harvested addressed from time to time
> + (notmuch-address-harvest-trigger)
> + (notmuch-address-matching arg))
> +(t
> + (cons :async
> +   (lambda (callback)
> + ;; First run quick asynchronous harvest based on 
> what the user entered so far
> + (notmuch-address-harvest
> +  (format "to:%s*" arg) nil
> +  (lambda (_proc _event)
> +(funcall callback (notmuch-address-matching arg))
> +;; Then (re)start potentially long-running full 
> asynchronous harvesting
> +(notmuch-address-harvest-trigger

I h

[Patch v5 1/3] Emacs: Add address completion mechanism implemented in elisp

2015-10-23 Thread David Bremner
From: Michal Sojka <sojk...@fel.cvut.cz>

Currently, notmuch has an address completion mechanism that requires
external command to provide completion candidates. This patch adds a
completion mechanism inspired by https://github.com/tjim/nevermore,
which is implemented in Emacs lisp only.

The preexisting address completion mechanism, activated by pressing TAB
on To/Cc lines, is extended to use the new mechanism when no external
command is configured, i.e. when notmuch-address-command to nil, which
is the new default.

The core of the new mechanism is the function notmuch-address-harvest,
which collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable. The address
harvesting can run either synchronously (same as with the previous
mechanism) or asynchronously. When the user presses TAB for the first
time, synchronous harvesting limited to user entered text is performed.
If the entered text is reasonably long, this operation is relatively
fast. Then, asynchronous harvesting over the full database is triggered.
This operation may take long time (minutes on rotating disk). After it
finishes, no harvesting is normally performed again and subsequent
completion requests use the harvested data cached in memory. Completion
cache is updated after 24 hours.

Note that the change of the notmuch-address-command default value
may *BREAK EXISTING SETUPS* when the user used external command named
"notmuch-addresses", i.e. the previous default. The result will be that
the user will use the new mechanism instead of the his command. I
believe that many users may not even recognize this because the new
mechanism works the same as
http://commonmeasure.org/~jkr/git/notmuch_addresses.git and perhaps also
as other commands suggested at
http://notmuchmail.org/emacstips/#address_completion.
---
 emacs/notmuch-address.el | 123 ---
 emacs/notmuch-lib.el |   3 ++
 2 files changed, 118 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index fde3c1b..9f6711b 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -20,14 +20,18 @@
 ;; Authors: David Edmondson <d...@dme.org>
 
 (require 'message)
+(require 'notmuch-query)
+(require 'notmuch-parser)
 
 ;;
 
-(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
+(defcustom notmuch-address-command nil
+  "The command which generates possible addresses for completion.
+It must take a single argument and output a list of possible
+matches, one per line. If set to nil, addresses are generated by
+a built-in completion mechanism."
+  :type '(radio (const :tag "No command: Use built-in completion" nil)
+(string :tag "Custom command" :value "notmuch-addresses"))
   :group 'notmuch-send
   :group 'notmuch-external)
 
@@ -42,6 +46,17 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defvar notmuch-address-last-harvest 0
+  "Time of last address harvest")
+
+(defvar notmuch-address-completions (make-hash-table :test 'equal)
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
+(defvar notmuch-address-full-harvest-finished nil
+  "t indicates that full completion address harvesting has been
+finished")
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -59,8 +74,32 @@ to know how address selection is made by default."
 (setq message-completion-alist
  (push notmuch-address-message-alist-member 
message-completion-alist
 
+(defun notmuch-address-matching (substring)
+  "Returns a list of completion candidates matching SUBSTRING.
+The candidates are taked form `notmuch-address-completions'."
+  (let ((candidates)
+   (re (regexp-quote substring)))
+(maphash (lambda (key val)
+  (when (string-match re key)
+(push key candidates)))
+notmuch-address-completions)
+candidates))
+
 (defun notmuch-address-options (original)
-  (process-lines notmuch-address-command original))
+  "Returns a list of completion candidates. Uses either
+elisp-based implementation or older implementation requiring
+external commands."
+  (cond
+   ((null notmuch-address-command)
+(when (not notmuch-address-full-harvest-finished)
+  ;; First, run quick synchronous harvest based on what the user
+  ;; entered so far
+  (notmuch-address-harvest (format "to:%s*" original) t))
+   

[Patch v5 3/3] Emacs: Add address completion based on company-mode

2015-10-23 Thread David Bremner
From: Michal Sojka <sojk...@fel.cvut.cz>

With this patch, address completion candidates are shown automatically
after short typing delay in a nice popup box. This requires company-mode
to be installed and it works only on Emacs >= 24. The completion is
based entirely on the asynchronous address harvesting from
notmuch-address.el so the GUI is theoretically not blocked for long
time.

The completion works similarly as the TAB-initiated completion from
notmuch-address.el, i.e. quick harvest based on user input is executed
first and only after full harvesting is finished, in-memory cached data
is used.

The notmuch-company.el is excluded from byte-compilation, because it
would require every person who want to compile notmuch to have
company-mode installed.
---
 emacs/Makefile.local |  6 +++-
 emacs/notmuch-company.el | 81 
 2 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 emacs/notmuch-company.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index 1109cfa..6c93e73 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -20,6 +20,7 @@ emacs_sources := \
$(dir)/notmuch-print.el \
$(dir)/notmuch-version.el \
$(dir)/notmuch-jump.el \
+   $(dir)/notmuch-company.el
 
 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
 $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
@@ -30,7 +31,10 @@ $(dir)/notmuch-version.el: 
$(srcdir)/$(dir)/notmuch-version.el.tmpl
 emacs_images := \
$(srcdir)/$(dir)/notmuch-logo.png
 
-emacs_bytecode = $(emacs_sources:.el=.elc)
+# Do not try to install files that are not byte-compiled.
+emacs_no_byte_compile := $(dir)/notmuch-company.el
+
+emacs_bytecode = $(patsubst %.el,%.elc,$(filter-out 
$(emacs_no_byte_compile),$(emacs_sources)))
 
 # Because of defmacro's and defsubst's, we have to account for load
 # dependencies between Elisp files when byte compiling.  Otherwise,
diff --git a/emacs/notmuch-company.el b/emacs/notmuch-company.el
new file mode 100644
index 000..f34aec4
--- /dev/null
+++ b/emacs/notmuch-company.el
@@ -0,0 +1,81 @@
+;; notmuch-company.el --- Mail address completion for notmuch via company-mode 
 -*- no-byte-compile: t; lexical-binding: t -*-
+
+
+;; Authors: Trevor Jim <t...@mac.com>
+;; Michal Sojka <sojk...@fel.cvut.cz>
+;;
+;; Keywords: mail, completion
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; To enable this, install company mode (https://company-mode.github.io/)
+;; and add
+;;
+;; (require 'notmuch-company)
+;;
+;; to your .emacs.
+;;
+;; NB company-minimum-prefix-length defaults to 3 so you don't get
+;; completion unless you type 3 characters
+
+;;; Code:
+
+(require 'company)
+(require 'message)
+(require 'notmuch-address)
+(require 'cl-lib)
+
+(defvar-local notmuch-company-last-prefix nil)
+
+;;;###autoload
+(defun notmuch-company (command  arg  ignore)
+  "`company-mode' completion back-end for `notmuch'."
+  (interactive (list 'interactive))
+  (let ((case-fold-search t)
+   (completion-ignore-case t))
+(cl-case command
+  (interactive (company-begin-backend 'notmuch-company))
+  (prefix (and (derived-mode-p 'message-mode)
+  (looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
+(line-beginning-position))
+  (setq notmuch-company-last-prefix (company-grab "[:,][ 
\t]*\\(.*\\)" 1 (point-at-bol)
+  (candidates (cond
+  (notmuch-address-full-harvest-finished
+   ;; Update harvested addressed from time to time
+   (notmuch-address-harvest-trigger)
+   (notmuch-address-matching arg))
+  (t
+   (cons :async
+ (lambda (callback)
+   ;; First run quick asynchronous harvest based on 
what the user entered so far
+   (notmuch-address-harvest
+(format "to:%s*" arg) nil
+(lambda (proc event)
+  (funcall callback (notmuch-address-matching arg))
+  ;; Then (re)start potentially long-running full 
asynchronous harvesting
+  (notm

elisp based address completion, round 5.

2015-10-23 Thread David Bremner
Changes since last round:

- resend as one series to (hopefully) reduce confusion
- update notmuch-company.el to use notmuch-message-mode
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [Patch v5 3/3] Emacs: Add address completion based on company-mode

2015-10-23 Thread David Bremner
David Bremner  writes:

> +;;;###autoload
> +(add-hook 'notmuch-message-mode-hook '(lambda ()
> + (company-mode)
> + (make-local-variable 'company-backends)
> + (setq company-backends 
> '(notmuch-company
> +
> +(provide 'notmuch-company)
> -- 

I know I just sent this message a few minutes ago, but I didn't write it
;).  Why is this second autoload cookie here? this means that in
principle this form will end up in the autoloads file.
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v4 1/3] Emacs: Display a message when generating address completion candidates

2015-01-18 Thread David Bremner
Michal Sojka  writes:

> The TAB-initiated address completion generates completion candidates
> synchronously, blocking the UI. Since this can take long time, it is
> better to let the use know what's happening.
> ---

Pushed this one patch.

d


Re: [PATCH v4 1/3] Emacs: Display a message when generating address completion candidates

2015-01-18 Thread David Bremner
Michal Sojka sojk...@fel.cvut.cz writes:

 The TAB-initiated address completion generates completion candidates
 synchronously, blocking the UI. Since this can take long time, it is
 better to let the use know what's happening.
 ---

Pushed this one patch.

d
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Address completion in Emacs

2014-12-14 Thread Tomi Ollila
On Fri, Dec 12 2014, Lele Gaifax wrote:

> Hi all,
>
> Yesterday I tweaked my Emacs configuration to use "ido-completing-read"
> to select the right address in the minibuffer, and noticed what seems a
> glitch in the related code.
>
> To accomplish the goal, I implemented my own selection function
>
>   (defun esk-notmuch-address-selection-function (prompt addresses first)
> "Use `ido-completing-read' to select one of the addresses."
> (ido-completing-read prompt (cons first addresses)
>  nil nil nil 'notmuch-address-history))
>
> and then assigned it to `notmuch-address-selection-function':
>
>   (setq notmuch-address-selection-function 
> 'esk-notmuch-address-selection-function)
>
> As you can see, I had to `cons' the two arguments, because the caller of
> that function does something similar to the following (where `orig' is
> the text entered before TAB-completion):
>
>   (options (notmuch-address-options orig))
>   (num-options (length options))
>   (chosen (funcall notmuch-address-selection-function
>   (format "Address (%s matches): " num-options)
>   (cdr options) (car options)))
>
> and the standard `notmuch-address-selection-function' is defined like:
>
>   (defun notmuch-address-selection-function (prompt collection initial-input)
> "Call (`completing-read'
> PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
> (completing-read
>  prompt collection nil nil initial-input 'notmuch-address-history))
>
> where that `initial-input' is not what I initially thought, the text
> entered by the user, but rather the first completion candidate.
>
> Wouldn't it be more "correct" to pass the unchanged `options' list and
> the "real" `orig' text as `initial-input' to the customizable function
> instead?

I think I am to be blamed why that is like this -- initially there were
no notmuch-address-selection-function ... I added as I needed it, in

Stashed: id:1365001734-3160-1-git-send-email-tomi.ollila at iki.fi
Stashed: http://mid.gmane.org/1365001734-3160-1-git-send-email-tomi.ollila at 
iki.fi

and I was not smart enough to do the splitting in "standard
notmuch-address-selection-function".  

Later, someone(*) provided patch which would make the "standard" interface
work better with ido-completing-read -- unfortunately that made the
default, original interface which uses completing-read borken.

Personally I'd like to see leaner interface there, but that is incompatible
change and in this particular case I don't see compelling reason to do that... 

(*) cannot remember who and when, and I am writing this mail on a Mac and
the use is painful enough now (keybindings, focus behaviour, etc...);/

>
> I understand that it may be undesiderable to break existing
> configurations by rectifying the arguments in that way, and in such case
> could we change the `initial-input' argument name to better reflect the
> fact that it actually contains one possible candidate instead?

Naming change would indeed be a good idea... (probably?!)  

>
> Thanks in advance for any clarification,
> ciao, lele.

Tomi

> -- 
> nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri
> real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia.
> lele at metapensiero.it  | -- Fortunato Depero, 1929.
>
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


Re: Address completion in Emacs

2014-12-14 Thread Tomi Ollila
On Fri, Dec 12 2014, Lele Gaifax wrote:

 Hi all,

 Yesterday I tweaked my Emacs configuration to use ido-completing-read
 to select the right address in the minibuffer, and noticed what seems a
 glitch in the related code.

 To accomplish the goal, I implemented my own selection function

   (defun esk-notmuch-address-selection-function (prompt addresses first)
 Use `ido-completing-read' to select one of the addresses.
 (ido-completing-read prompt (cons first addresses)
  nil nil nil 'notmuch-address-history))

 and then assigned it to `notmuch-address-selection-function':

   (setq notmuch-address-selection-function 
 'esk-notmuch-address-selection-function)

 As you can see, I had to `cons' the two arguments, because the caller of
 that function does something similar to the following (where `orig' is
 the text entered before TAB-completion):

   (options (notmuch-address-options orig))
   (num-options (length options))
   (chosen (funcall notmuch-address-selection-function
   (format Address (%s matches):  num-options)
   (cdr options) (car options)))

 and the standard `notmuch-address-selection-function' is defined like:

   (defun notmuch-address-selection-function (prompt collection initial-input)
 Call (`completing-read'
 PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)
 (completing-read
  prompt collection nil nil initial-input 'notmuch-address-history))

 where that `initial-input' is not what I initially thought, the text
 entered by the user, but rather the first completion candidate.

 Wouldn't it be more correct to pass the unchanged `options' list and
 the real `orig' text as `initial-input' to the customizable function
 instead?

I think I am to be blamed why that is like this -- initially there were
no notmuch-address-selection-function ... I added as I needed it, in

Stashed: id:1365001734-3160-1-git-send-email-tomi.oll...@iki.fi
Stashed: 
http://mid.gmane.org/1365001734-3160-1-git-send-email-tomi.oll...@iki.fi

and I was not smart enough to do the splitting in standard
notmuch-address-selection-function.  

Later, someone(*) provided patch which would make the standard interface
work better with ido-completing-read -- unfortunately that made the
default, original interface which uses completing-read borken.

Personally I'd like to see leaner interface there, but that is incompatible
change and in this particular case I don't see compelling reason to do that... 

(*) cannot remember who and when, and I am writing this mail on a Mac and
the use is painful enough now (keybindings, focus behaviour, etc...);/


 I understand that it may be undesiderable to break existing
 configurations by rectifying the arguments in that way, and in such case
 could we change the `initial-input' argument name to better reflect the
 fact that it actually contains one possible candidate instead?

Naming change would indeed be a good idea... (probably?!)  


 Thanks in advance for any clarification,
 ciao, lele.

Tomi

 -- 
 nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
 real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
 l...@metapensiero.it  | -- Fortunato Depero, 1929.

 ___
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Address completion in Emacs

2014-12-12 Thread Lele Gaifax
David Edmondson  writes:

> On Fri, Dec 12 2014, Lele Gaifax wrote:
>> Wouldn't it be more "correct" to pass the unchanged `options' list and
>> the "real" `orig' text as `initial-input' to the customizable function
>> instead?
>
> Would I then have to press TAB twice to get the first result?

No, why? The customizable `notmuch-address-selection-function' would be
free to pass (car options) as the initial-input of `completing-read', if
needed. When using `ido-completing-read', the first option is
pre-selected, so a RET confirms that.

>> I understand that it may be undesiderable to break existing
>> configurations by rectifying the arguments in that way, and in such case
>> could we change the `initial-input' argument name to better reflect the
>> fact that it actually contains one possible candidate instead?
>
> From the perspective of `notmuch-address-selection-function', it _is_
> the `initial-input', as that is what is presented to the user.

IMHO no, it's not: what it receives as `initial-input' is not what the
user actually wrote, but rather just the (somewhat arbitrary) first
candidate address found by `notmuch-address-command'.

thanks, lele.
-- 
nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri
real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia.
lele at metapensiero.it  | -- Fortunato Depero, 1929.



Address completion in Emacs

2014-12-12 Thread David Edmondson
On Fri, Dec 12 2014, Lele Gaifax wrote:
> David Edmondson  writes:
>
>> On Fri, Dec 12 2014, Lele Gaifax wrote:
>>> Wouldn't it be more "correct" to pass the unchanged `options' list and
>>> the "real" `orig' text as `initial-input' to the customizable function
>>> instead?
>>
>> Would I then have to press TAB twice to get the first result?
>
> No, why? The customizable `notmuch-address-selection-function' would be
> free to pass (car options) as the initial-input of `completing-read', if
> needed. When using `ido-completing-read', the first option is
> pre-selected, so a RET confirms that.

Understood.

>>> I understand that it may be undesiderable to break existing
>>> configurations by rectifying the arguments in that way, and in such case
>>> could we change the `initial-input' argument name to better reflect the
>>> fact that it actually contains one possible candidate instead?
>>
>> From the perspective of `notmuch-address-selection-function', it _is_
>> the `initial-input', as that is what is presented to the user.
>
> IMHO no, it's not: what it receives as `initial-input' is not what the
> user actually wrote, but rather just the (somewhat arbitrary) first
> candidate address found by `notmuch-address-command'.

I think that we're at cross
purposes. `notmuch-address-selection-function' will use the
`initial-input' as the initial input of the completion, so that's what
it chooses to call the argument. It can't be blamed if whatever is
passed to it is not something that you would consider the initial input.

> thanks, lele.
> -- 
> nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri
> real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia.
> lele at metapensiero.it  | -- Fortunato Depero, 1929.
>
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


Address completion in Emacs

2014-12-12 Thread David Edmondson
On Fri, Dec 12 2014, Lele Gaifax wrote:
> Hi all,
>
> Yesterday I tweaked my Emacs configuration to use "ido-completing-read"
> to select the right address in the minibuffer, and noticed what seems a
> glitch in the related code.
>
> To accomplish the goal, I implemented my own selection function
>
>   (defun esk-notmuch-address-selection-function (prompt addresses first)
> "Use `ido-completing-read' to select one of the addresses."
> (ido-completing-read prompt (cons first addresses)
>  nil nil nil 'notmuch-address-history))
>
> and then assigned it to `notmuch-address-selection-function':
>
>   (setq notmuch-address-selection-function 
> 'esk-notmuch-address-selection-function)
>
> As you can see, I had to `cons' the two arguments, because the caller of
> that function does something similar to the following (where `orig' is
> the text entered before TAB-completion):
>
>   (options (notmuch-address-options orig))
>   (num-options (length options))
>   (chosen (funcall notmuch-address-selection-function
>   (format "Address (%s matches): " num-options)
>   (cdr options) (car options)))
>
> and the standard `notmuch-address-selection-function' is defined like:
>
>   (defun notmuch-address-selection-function (prompt collection initial-input)
> "Call (`completing-read'
> PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
> (completing-read
>  prompt collection nil nil initial-input 'notmuch-address-history))
>
> where that `initial-input' is not what I initially thought, the text
> entered by the user, but rather the first completion candidate.
>
> Wouldn't it be more "correct" to pass the unchanged `options' list and
> the "real" `orig' text as `initial-input' to the customizable function
> instead?

Would I then have to press TAB twice to get the first result?

> I understand that it may be undesiderable to break existing
> configurations by rectifying the arguments in that way, and in such case
> could we change the `initial-input' argument name to better reflect the
> fact that it actually contains one possible candidate instead?

>From the perspective of `notmuch-address-selection-function', it _is_
the `initial-input', as that is what is presented to the user.

> Thanks in advance for any clarification,
> ciao, lele.
> -- 
> nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri
> real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia.
> lele at metapensiero.it  | -- Fortunato Depero, 1929.
>
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


Address completion in Emacs

2014-12-12 Thread Lele Gaifax
Hi all,

Yesterday I tweaked my Emacs configuration to use "ido-completing-read"
to select the right address in the minibuffer, and noticed what seems a
glitch in the related code.

To accomplish the goal, I implemented my own selection function

  (defun esk-notmuch-address-selection-function (prompt addresses first)
"Use `ido-completing-read' to select one of the addresses."
(ido-completing-read prompt (cons first addresses)
 nil nil nil 'notmuch-address-history))

and then assigned it to `notmuch-address-selection-function':

  (setq notmuch-address-selection-function 
'esk-notmuch-address-selection-function)

As you can see, I had to `cons' the two arguments, because the caller of
that function does something similar to the following (where `orig' is
the text entered before TAB-completion):

  (options (notmuch-address-options orig))
  (num-options (length options))
  (chosen (funcall notmuch-address-selection-function
  (format "Address (%s matches): " num-options)
  (cdr options) (car options)))

and the standard `notmuch-address-selection-function' is defined like:

  (defun notmuch-address-selection-function (prompt collection initial-input)
"Call (`completing-read'
PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
(completing-read
 prompt collection nil nil initial-input 'notmuch-address-history))

where that `initial-input' is not what I initially thought, the text
entered by the user, but rather the first completion candidate.

Wouldn't it be more "correct" to pass the unchanged `options' list and
the "real" `orig' text as `initial-input' to the customizable function
instead?

I understand that it may be undesiderable to break existing
configurations by rectifying the arguments in that way, and in such case
could we change the `initial-input' argument name to better reflect the
fact that it actually contains one possible candidate instead?

Thanks in advance for any clarification,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri
real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia.
lele at metapensiero.it  | -- Fortunato Depero, 1929.



Address completion in Emacs

2014-12-12 Thread Lele Gaifax
Hi all,

Yesterday I tweaked my Emacs configuration to use ido-completing-read
to select the right address in the minibuffer, and noticed what seems a
glitch in the related code.

To accomplish the goal, I implemented my own selection function

  (defun esk-notmuch-address-selection-function (prompt addresses first)
Use `ido-completing-read' to select one of the addresses.
(ido-completing-read prompt (cons first addresses)
 nil nil nil 'notmuch-address-history))

and then assigned it to `notmuch-address-selection-function':

  (setq notmuch-address-selection-function 
'esk-notmuch-address-selection-function)

As you can see, I had to `cons' the two arguments, because the caller of
that function does something similar to the following (where `orig' is
the text entered before TAB-completion):

  (options (notmuch-address-options orig))
  (num-options (length options))
  (chosen (funcall notmuch-address-selection-function
  (format Address (%s matches):  num-options)
  (cdr options) (car options)))

and the standard `notmuch-address-selection-function' is defined like:

  (defun notmuch-address-selection-function (prompt collection initial-input)
Call (`completing-read'
PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)
(completing-read
 prompt collection nil nil initial-input 'notmuch-address-history))

where that `initial-input' is not what I initially thought, the text
entered by the user, but rather the first completion candidate.

Wouldn't it be more correct to pass the unchanged `options' list and
the real `orig' text as `initial-input' to the customizable function
instead?

I understand that it may be undesiderable to break existing
configurations by rectifying the arguments in that way, and in such case
could we change the `initial-input' argument name to better reflect the
fact that it actually contains one possible candidate instead?

Thanks in advance for any clarification,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: Address completion in Emacs

2014-12-12 Thread David Edmondson
On Fri, Dec 12 2014, Lele Gaifax wrote:
 Hi all,

 Yesterday I tweaked my Emacs configuration to use ido-completing-read
 to select the right address in the minibuffer, and noticed what seems a
 glitch in the related code.

 To accomplish the goal, I implemented my own selection function

   (defun esk-notmuch-address-selection-function (prompt addresses first)
 Use `ido-completing-read' to select one of the addresses.
 (ido-completing-read prompt (cons first addresses)
  nil nil nil 'notmuch-address-history))

 and then assigned it to `notmuch-address-selection-function':

   (setq notmuch-address-selection-function 
 'esk-notmuch-address-selection-function)

 As you can see, I had to `cons' the two arguments, because the caller of
 that function does something similar to the following (where `orig' is
 the text entered before TAB-completion):

   (options (notmuch-address-options orig))
   (num-options (length options))
   (chosen (funcall notmuch-address-selection-function
   (format Address (%s matches):  num-options)
   (cdr options) (car options)))

 and the standard `notmuch-address-selection-function' is defined like:

   (defun notmuch-address-selection-function (prompt collection initial-input)
 Call (`completing-read'
 PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)
 (completing-read
  prompt collection nil nil initial-input 'notmuch-address-history))

 where that `initial-input' is not what I initially thought, the text
 entered by the user, but rather the first completion candidate.

 Wouldn't it be more correct to pass the unchanged `options' list and
 the real `orig' text as `initial-input' to the customizable function
 instead?

Would I then have to press TAB twice to get the first result?

 I understand that it may be undesiderable to break existing
 configurations by rectifying the arguments in that way, and in such case
 could we change the `initial-input' argument name to better reflect the
 fact that it actually contains one possible candidate instead?

From the perspective of `notmuch-address-selection-function', it _is_
the `initial-input', as that is what is presented to the user.

 Thanks in advance for any clarification,
 ciao, lele.
 -- 
 nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
 real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
 l...@metapensiero.it  | -- Fortunato Depero, 1929.

 ___
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


  1   2   3   >