[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-08-11 Thread Michal Sojka
Hi David,

On Fri, Aug 01 2014, David Bremner wrote:
> Michal Sojka  writes:
>
>> notmuch-company.el hooks itself into message-mode and uses
>> company-mode to offer the completion to the user. The file is put into
>> the contrib directory which means that the use has to install it
>> himself. This is because company-mode is not a part of Emacs and
>> bytecompiling notmuch-company.el fails due to used --quick option that
>> causes user installed packages to be ignored. 
>
> what about for now just putting 
>
> ;; -*-no-byte-compile: t; -*-
>
> at the top of the file?  It seems usable uncompiled to me.
>
> Then somebody who really wants it compiled can figure out how to do the
> conditional compilation.
>
>> It would probably make sense to implement another completion frontend
>> based only on Emacs built-in functionality and integrate it with
>> notmuch-addresses.el.
>
> Agreed.
>
>> +  "`company-mode' completion back-end for `nevermore (nm)'."
>
> missed "nevermore" ;)
>
>
>>  
>> +(defun notmuch-flatten-thread-set (thread-set)
>> +  "Convert the result of 'notmuch show' to the plain list of messages."
>> +(defun notmuch-flatten-thread (thread)
>> +
>> +(defun notmuch-flatten-thread-node (thread-node)
>
>
> what about putting those functions in notmuch-query.el?
>
>
>> +(defun notmuch-async-harvest ()
>> +  "Collect possible addresses for completion. It queries the
>
>
> logically it seems like this might belong in notmuch-address.el,
> even if none of the functions in  in it currently use

Thanks for the comments. I incorporated them in a new version of the
patch, which I'll send in a while.

-Michal


Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-08-11 Thread Michal Sojka
Hi David,

On Fri, Aug 01 2014, David Bremner wrote:
 Michal Sojka sojk...@fel.cvut.cz writes:

 notmuch-company.el hooks itself into message-mode and uses
 company-mode to offer the completion to the user. The file is put into
 the contrib directory which means that the use has to install it
 himself. This is because company-mode is not a part of Emacs and
 bytecompiling notmuch-company.el fails due to used --quick option that
 causes user installed packages to be ignored. 

 what about for now just putting 

 ;; -*-no-byte-compile: t; -*-

 at the top of the file?  It seems usable uncompiled to me.

 Then somebody who really wants it compiled can figure out how to do the
 conditional compilation.

 It would probably make sense to implement another completion frontend
 based only on Emacs built-in functionality and integrate it with
 notmuch-addresses.el.

 Agreed.

 +  `company-mode' completion back-end for `nevermore (nm)'.

 missed nevermore ;)


  
 +(defun notmuch-flatten-thread-set (thread-set)
 +  Convert the result of 'notmuch show' to the plain list of messages.
 +(defun notmuch-flatten-thread (thread)
 +
 +(defun notmuch-flatten-thread-node (thread-node)


 what about putting those functions in notmuch-query.el?


 +(defun notmuch-async-harvest ()
 +  Collect possible addresses for completion. It queries the


 logically it seems like this might belong in notmuch-address.el,
 even if none of the functions in  in it currently use

Thanks for the comments. I incorporated them in a new version of the
patch, which I'll send in a while.

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


[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-31 Thread David Bremner
Michal Sojka  writes:

> notmuch-company.el hooks itself into message-mode and uses
> company-mode to offer the completion to the user. The file is put into
> the contrib directory which means that the use has to install it
> himself. This is because company-mode is not a part of Emacs and
> bytecompiling notmuch-company.el fails due to used --quick option that
> causes user installed packages to be ignored. 

what about for now just putting 

;; -*-no-byte-compile: t; -*-

at the top of the file?  It seems usable uncompiled to me.

Then somebody who really wants it compiled can figure out how to do the
conditional compilation.

> It would probably make sense to implement another completion frontend
> based only on Emacs built-in functionality and integrate it with
> notmuch-addresses.el.

Agreed.

> +  "`company-mode' completion back-end for `nevermore (nm)'."

missed "nevermore" ;)


>  
> +(defun notmuch-flatten-thread-set (thread-set)
> +  "Convert the result of 'notmuch show' to the plain list of messages."
> +(defun notmuch-flatten-thread (thread)
> +
> +(defun notmuch-flatten-thread-node (thread-node)


what about putting those functions in notmuch-query.el?


> +(defun notmuch-async-harvest ()
> +  "Collect possible addresses for completion. It queries the


logically it seems like this might belong in notmuch-address.el,
even if none of the functions in  in it currently use


d


[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-31 Thread Michal Sojka
On Thu, Jul 31 2014, Trevor Jim wrote:
> BTW I have been refactoring my async process code. You might consider
> it for your patch.

I'll look at that. I figured out that I might also reuse
notmuch-parser.el. I'll post here my findings later.

-Michal


Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-31 Thread Michal Sojka
On Thu, Jul 31 2014, Trevor Jim wrote:
 BTW I have been refactoring my async process code. You might consider
 it for your patch.

I'll look at that. I figured out that I might also reuse
notmuch-parser.el. I'll post here my findings later.

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


Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-31 Thread David Bremner
Michal Sojka sojk...@fel.cvut.cz writes:

 notmuch-company.el hooks itself into message-mode and uses
 company-mode to offer the completion to the user. The file is put into
 the contrib directory which means that the use has to install it
 himself. This is because company-mode is not a part of Emacs and
 bytecompiling notmuch-company.el fails due to used --quick option that
 causes user installed packages to be ignored. 

what about for now just putting 

;; -*-no-byte-compile: t; -*-

at the top of the file?  It seems usable uncompiled to me.

Then somebody who really wants it compiled can figure out how to do the
conditional compilation.

 It would probably make sense to implement another completion frontend
 based only on Emacs built-in functionality and integrate it with
 notmuch-addresses.el.

Agreed.

 +  `company-mode' completion back-end for `nevermore (nm)'.

missed nevermore ;)


  
 +(defun notmuch-flatten-thread-set (thread-set)
 +  Convert the result of 'notmuch show' to the plain list of messages.
 +(defun notmuch-flatten-thread (thread)
 +
 +(defun notmuch-flatten-thread-node (thread-node)


what about putting those functions in notmuch-query.el?


 +(defun notmuch-async-harvest ()
 +  Collect possible addresses for completion. It queries the


logically it seems like this might belong in notmuch-address.el,
even if none of the functions in  in it currently use


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


[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-30 Thread Michal Sojka
On Wed, Jul 30 2014, David Bremner wrote:
> Michal Sojka  writes:
>
>> Notmuch currently has an address completion mechanism that requires
>> external script to provide completion candidates. This patch adds a
>> completion mechanism found in https://github.com/tjim/nevermore, which
>> is implemented in elisp only.
>
> I was playing with this a bit and I noticed that for very long
> completion lists, after scrolling down for a while, it get stuck, and up
> or down arrow yields no movement messages like
>
> ,
> | Company: Front-end company-pseudo-tooltip-unless-just-one-frontend error 
> "Args out of range: 1, 124" on command update [2 times]
> | Mark set
> `
>
> Not sure if this is a company problem or a problem with the use of
> company.
>
> I have company-0.8.1 from elpa.

Yes. I contacted company-mode maintainer with this problem and it is now
fixed in git. It's not yet released though. See
https://github.com/company-mode/company-mode/issues/156.

-Micahl


Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-30 Thread Trevor Jim
BTW I have been refactoring my async process code. You might consider it for 
your patch.
-Trevor
?
-- next part --
An HTML attachment was scrubbed...
URL: 



Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-30 Thread David Bremner
Michal Sojka sojk...@fel.cvut.cz writes:

 Notmuch currently has an address completion mechanism that requires
 external script to provide completion candidates. This patch adds a
 completion mechanism found in https://github.com/tjim/nevermore, which
 is implemented in elisp only.

I was playing with this a bit and I noticed that for very long
completion lists, after scrolling down for a while, it get stuck, and up
or down arrow yields no movement messages like

,
| Company: Front-end company-pseudo-tooltip-unless-just-one-frontend error 
Args out of range: 1, 124 on command update [2 times]
| Mark set
`

Not sure if this is a company problem or a problem with the use of
company.

I have company-0.8.1 from elpa.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-30 Thread Michal Sojka
On Wed, Jul 30 2014, David Bremner wrote:
 Michal Sojka sojk...@fel.cvut.cz writes:

 Notmuch currently has an address completion mechanism that requires
 external script to provide completion candidates. This patch adds a
 completion mechanism found in https://github.com/tjim/nevermore, which
 is implemented in elisp only.

 I was playing with this a bit and I noticed that for very long
 completion lists, after scrolling down for a while, it get stuck, and up
 or down arrow yields no movement messages like

 ,
 | Company: Front-end company-pseudo-tooltip-unless-just-one-frontend error 
 Args out of range: 1, 124 on command update [2 times]
 | Mark set
 `

 Not sure if this is a company problem or a problem with the use of
 company.

 I have company-0.8.1 from elpa.

Yes. I contacted company-mode maintainer with this problem and it is now
fixed in git. It's not yet released though. See
https://github.com/company-mode/company-mode/issues/156.

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


Re: [PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-30 Thread Trevor Jim

BTW I have been refactoring my async process code. You might consider it for 
your patch.
-Trevor

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


[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-29 Thread David Bremner
Michal Sojka  writes:

> Notmuch currently has an address completion mechanism that requires
> external script to provide completion candidates. This patch adds a
> completion mechanism found in https://github.com/tjim/nevermore, which
> is implemented in elisp only.

I was playing with this a bit and I noticed that for very long
completion lists, after scrolling down for a while, it get stuck, and up
or down arrow yields no movement messages like

,
| Company: Front-end company-pseudo-tooltip-unless-just-one-frontend error 
"Args out of range: 1, 124" on command update [2 times]
| Mark set
`

Not sure if this is a company problem or a problem with the use of
company.

I have company-0.8.1 from elpa.


[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-29 Thread Michal Sojka
Notmuch currently has an address completion mechanism that requires
external script to provide completion candidates. This patch adds a
completion mechanism found in https://github.com/tjim/nevermore, which
is implemented in elisp only.

notmuch-lib.el is extended with function notmuch-async-harvest that
collects the completion candidates from notmuch database and stores
them in notmuch-completion-addresses.

notmuch-company.el hooks itself into message-mode and uses
company-mode to offer the completion to the user. The file is put into
the contrib directory which means that the use has to install it
himself. This is because company-mode is not a part of Emacs and
bytecompiling notmuch-company.el fails due to used --quick option that
causes user installed packages to be ignored. Moreover, Debian
bytecompiles elisp files during installation which would require
having company-mode packaged for Debian. This would be possible but
company-mode requires emacs24 which would complicate notmuch Debian
maintainer scripts.

It would probably make sense to implement another completion frontend
based only on Emacs built-in functionality and integrate it with
notmuch-addresses.el.

The original  nevermore code was modified in the following ways:
1) Prefix was changes from nm- to notmuch-.
2) A few docstrings and comments were added.
3) notmuch-flatten-* functions were renamed to match match
   devel/schemata.
---
 debian/notmuch-emacs.examples|  1 +
 emacs/contrib/notmuch-company.el | 62 
 emacs/notmuch-lib.el | 87 
 3 files changed, 150 insertions(+)
 create mode 100644 debian/notmuch-emacs.examples
 create mode 100644 emacs/contrib/notmuch-company.el

diff --git a/debian/notmuch-emacs.examples b/debian/notmuch-emacs.examples
new file mode 100644
index 000..4a42a47
--- /dev/null
+++ b/debian/notmuch-emacs.examples
@@ -0,0 +1 @@
+emacs/contrib/notmuch-company.el
diff --git a/emacs/contrib/notmuch-company.el b/emacs/contrib/notmuch-company.el
new file mode 100644
index 000..228de94
--- /dev/null
+++ b/emacs/contrib/notmuch-company.el
@@ -0,0 +1,62 @@
+;; notmuch-company.el --- Mail address completion for notmuch via company-mode
+
+;; Author: Trevor Jim 
+;; 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 .
+
+;;; 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-lib)
+
+(defvar-local notmuch-company-last-prefix nil)
+;;;###autoload
+(defun notmuch-company (command  arg  ignore)
+  "`company-mode' completion back-end for `nevermore (nm)'."
+  (interactive (list 'interactive))
+  (let ((case-fold-search t))
+(pcase command
+  (`interactive (company-begin-backend 'notmuch-company))
+  (`prefix (and (eq major-mode 'message-mode)
+(looking-back "^\\(To\\|Cc\\|Bcc\\):.*"
+  (line-beginning-position))
+(setq notmuch-company-last-prefix (company-grab-symbol
+  (`candidates (let ((results (completion-substring--all-completions arg 
notmuch-completion-addresses nil 0)))
+ (when results (car results
+  (`match (if (string-match notmuch-company-last-prefix arg)
+  (match-end 0)
+0))
+  (`no-cache t
+
+(add-hook 'message-mode-hook '(lambda ()
+(company-mode)
+(make-local-variable 'company-backends)
+(setq company-backends '(notmuch-company))
+   (when (not notmuch-completion-addresses) 
(notmuch-async-harvest
+(provide 'notmuch-company)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2941da3..c0f4ba0 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -216,6 +216,9 @@ on the command line, and then retry your notmuch command")))
   "Return the user.other_email value (as a list) from the notmuch 
configuration."
   (split-string (notmuch-config-get "user.other_email") "\n" t))

+(defun notmuch-user-emails ()
+  

[PATCH RFC] Emacs: Add address completion mechanism implemented in elisp

2014-07-29 Thread Michal Sojka
Notmuch currently has an address completion mechanism that requires
external script to provide completion candidates. This patch adds a
completion mechanism found in https://github.com/tjim/nevermore, which
is implemented in elisp only.

notmuch-lib.el is extended with function notmuch-async-harvest that
collects the completion candidates from notmuch database and stores
them in notmuch-completion-addresses.

notmuch-company.el hooks itself into message-mode and uses
company-mode to offer the completion to the user. The file is put into
the contrib directory which means that the use has to install it
himself. This is because company-mode is not a part of Emacs and
bytecompiling notmuch-company.el fails due to used --quick option that
causes user installed packages to be ignored. Moreover, Debian
bytecompiles elisp files during installation which would require
having company-mode packaged for Debian. This would be possible but
company-mode requires emacs24 which would complicate notmuch Debian
maintainer scripts.

It would probably make sense to implement another completion frontend
based only on Emacs built-in functionality and integrate it with
notmuch-addresses.el.

The original  nevermore code was modified in the following ways:
1) Prefix was changes from nm- to notmuch-.
2) A few docstrings and comments were added.
3) notmuch-flatten-* functions were renamed to match match
   devel/schemata.
---
 debian/notmuch-emacs.examples|  1 +
 emacs/contrib/notmuch-company.el | 62 
 emacs/notmuch-lib.el | 87 
 3 files changed, 150 insertions(+)
 create mode 100644 debian/notmuch-emacs.examples
 create mode 100644 emacs/contrib/notmuch-company.el

diff --git a/debian/notmuch-emacs.examples b/debian/notmuch-emacs.examples
new file mode 100644
index 000..4a42a47
--- /dev/null
+++ b/debian/notmuch-emacs.examples
@@ -0,0 +1 @@
+emacs/contrib/notmuch-company.el
diff --git a/emacs/contrib/notmuch-company.el b/emacs/contrib/notmuch-company.el
new file mode 100644
index 000..228de94
--- /dev/null
+++ b/emacs/contrib/notmuch-company.el
@@ -0,0 +1,62 @@
+;; notmuch-company.el --- Mail address completion for notmuch via company-mode
+
+;; Author: Trevor Jim t...@mac.com
+;; 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-lib)
+
+(defvar-local notmuch-company-last-prefix nil)
+;;;###autoload
+(defun notmuch-company (command optional arg rest ignore)
+  `company-mode' completion back-end for `nevermore (nm)'.
+  (interactive (list 'interactive))
+  (let ((case-fold-search t))
+(pcase command
+  (`interactive (company-begin-backend 'notmuch-company))
+  (`prefix (and (eq major-mode 'message-mode)
+(looking-back ^\\(To\\|Cc\\|Bcc\\):.*
+  (line-beginning-position))
+(setq notmuch-company-last-prefix (company-grab-symbol
+  (`candidates (let ((results (completion-substring--all-completions arg 
notmuch-completion-addresses nil 0)))
+ (when results (car results
+  (`match (if (string-match notmuch-company-last-prefix arg)
+  (match-end 0)
+0))
+  (`no-cache t
+
+(add-hook 'message-mode-hook '(lambda ()
+(company-mode)
+(make-local-variable 'company-backends)
+(setq company-backends '(notmuch-company))
+   (when (not notmuch-completion-addresses) 
(notmuch-async-harvest
+(provide 'notmuch-company)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2941da3..c0f4ba0 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -216,6 +216,9 @@ on the command line, and then retry your notmuch command)))
   Return the user.other_email value (as a list) from the notmuch 
configuration.
   (split-string (notmuch-config-get user.other_email) \n t))
 
+(defun