`notmuch-escape-boolean-term': Broken for non-ascii characters

2014-08-11 Thread Moritz Ulrich

Hello,

I recently adopted notmuch as my primary way to read mail, so thank you
for this great tool!

Unfortunately, I ran into a problem of the Emacs side of the project
when used in a non-ascii environment:

Having a tag named 'uni-k?ln', the tag:-completion doesn't work.

This is caused by `notmuch-escape-boolean-term' errornously escaping the
above string:

(notmuch-escape-boolean-term "uni-k?ln") => "\"uni-k?ln\""

This is caused by `string-match' with the following errornously matching
my tag:

(string-match "[^!#-'*-~]" "uni-k?ln") => 5
(string-match "[^!#-'*-~]" "uni-koln") => nil

I'm not exactly sure how to tackle this - the Regexp was crafted to match
(, ), " if I understand it correct. A simple way would be just adding
more characters as a sort-of whitelist. A nicer solution would be
converting it from [^...] to [...] to explicitly mark letters that needs
to be escaped.

Cheers,
Moritz Ulrich
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20140811/5be67b1f/attachment.pgp>


Matching on any header line

2014-08-11 Thread David Bremner
Nico Schottelius  writes:

> David Bremner [Mon, Aug 11, 2014 at 01:37:50PM -0300]:
>> Nico Schottelius  writes:
>> 
>> > I have the problem that often To/Cc do not reveal the real destination,
>> > so I would like to match on X-Original-To: or Delivered-To:
>> > header lines.
>> >
>> > So I was wondering, if there is generic support to match on something
>> > like "header:x-original-to:this at example.org"?
>> 
>> Such support does not currently exist in notmuch.
>
> Too bad - if you are in general open for it, I will add it to my
> "to hack" list.

I _think_ the concensus was that want to configure the set of headers
indexed, mainly based on worries about bloating the database.  At least,
certain long headers like Received would most likely need to be
blacklisted.

d


Matching on any header line

2014-08-11 Thread Nico Schottelius
David Bremner [Mon, Aug 11, 2014 at 01:37:50PM -0300]:
> Nico Schottelius  writes:
> 
> > I have the problem that often To/Cc do not reveal the real destination,
> > so I would like to match on X-Original-To: or Delivered-To:
> > header lines.
> >
> > So I was wondering, if there is generic support to match on something
> > like "header:x-original-to:this at example.org"?
> 
> Such support does not currently exist in notmuch.

Too bad - if you are in general open for it, I will add it to my
"to hack" list.

Cheers,

Nico

-- 
New PGP key: 659B 0D91 E86E 7E24 FD15  69D0 C729 21A1 293F 2D24


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

2014-08-11 Thread Michal Sojka
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 core of the new mechanism is the function notmuch-address-harvest
that collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable.
notmuch-address-harvest is called on the first entry to message-mode
and runs asychnornously so that the user doesn't have to wait for it
to complete while composing the message. The
notmuch-address-completions variable is used in message-mode as a
source of completion candidates. Currently, there are two ways how the
notmuch-address-completions variable is used.

First, preexisting address completion mechanism is extended to use
notmuch-address-completions in addition to the external command. This
new behavior is configured by setting notmuch-address-command to nil,
which is the new default. Note that this 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.

Second way of using notmuch-address-completions is notmuch-company.el.
This presents the possible completions in a nice popup box after a
short typing delay but requires company-mode to be installed.

---
Changes from v1:
- Use of notmuch-parser.el instead of the custom parser in the
  original code. The notmuch parser is slightly faster.
- Use of functions in notmuch-query.el instead of functions in the
  original code with almost the same functionality.
- Integrated with existing completion mechanism in notmuch.
- notmuch-company.el was moved from emacs/contrib to emacs and
  no-byte-compile directive was added to it.
- Aligned with notmuch naming conventions.
- Documented bugs found in notmuch-company.el

Changes from v2:
- Updated Makefile.local to not conflict with current master
---
 emacs/Makefile.local |  6 ++-
 emacs/notmuch-address.el | 95 +++-
 emacs/notmuch-company.el | 69 +++
 emacs/notmuch-lib.el |  3 ++
 4 files changed, 163 insertions(+), 10 deletions(-)
 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-address.el b/emacs/notmuch-address.el
index fa65cd5..a50f4f4 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -20,14 +20,18 @@
 ;; Authors: David Edmondson 

 (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,10 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)

+(defvar notmuch-address-completions nil
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call 

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

2014-08-11 Thread Michal Sojka
On Mon, Aug 11 2014, Michal Sojka wrote:
> 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.

Sorry, this doesn't apply to current master. I'll resend an updated
version.

-Michal



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

2014-08-11 Thread Michal Sojka
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 core of the new mechanism is the function notmuch-address-harvest
that collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable.
notmuch-address-harvest is called on the first entry to message-mode
and runs asychnornously so that the user doesn't have to wait for it
to complete while composing the message. The
notmuch-address-completions variable is used in message-mode as a
source of completion candidates. Currently, there are two ways how the
notmuch-address-completions variable is used.

First, preexisting address completion mechanism is extended to use
notmuch-address-completions in addition to the external command. This
new behavior is configured by setting notmuch-address-command to nil,
which is the new default. Note that this 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.

Second way of using notmuch-address-completions is notmuch-company.el.
This presents the possible completions in a nice popup box after a
short typing delay but requires company-mode to be installed.

Changes from v1:
- Use of notmuch-parser.el instead of the custom parser in the
  original code. The notmuch parser is slightly faster.
- Use of functions in notmuch-query.el instead of functions in the
  original code with almost the same functionality.
- Integrated with existing completion mechanism in notmuch.
- notmuch-company.el was moved from emacs/contrib to emacs and
  no-byte-compile directive was added to it.
- Aligned with notmuch naming conventions.
- Documented bugs found in notmuch-company.el
---
 emacs/Makefile.local |  6 ++-
 emacs/notmuch-address.el | 95 +++-
 emacs/notmuch-company.el | 69 +++
 emacs/notmuch-lib.el |  3 ++
 4 files changed, 163 insertions(+), 10 deletions(-)
 create mode 100644 emacs/notmuch-company.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index c0d6b19..9214d6e 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -18,6 +18,7 @@ emacs_sources := \
$(dir)/notmuch-tag.el \
$(dir)/coolj.el \
$(dir)/notmuch-print.el \
+   $(dir)/notmuch-company.el \
$(dir)/notmuch-version.el

 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
@@ -29,7 +30,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-address.el b/emacs/notmuch-address.el
index fa65cd5..a50f4f4 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -20,14 +20,18 @@
 ;; Authors: David Edmondson 

 (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,10 @@ to know how address selection is made by default."
   :group 'notmuch-send
   :group 'notmuch-external)

+(defvar notmuch-address-completions nil
+  "Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.")
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   "Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)"
@@ -60,7 +68,16 @@ to know how address selection 

[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


DatabaseModifiedErrors causing troubles

2014-08-11 Thread Gaute Hope
Hi,

I've been working on an application that keeps a read-only handle on
the notmuch database open for a long time. In some cases when a new
message is added along with some renames of other messages using
'notmuch new' while the application is running I get an Xapian
exception: DatabaseModifiedError:

  A Xapian exception occurred performing query: The revision being
read has been discarded - you
  should call Xapian::Database::reopen() and retry the operation.

Which seems to be printed from: notmuch_query_search_threads ->
notmuch_query_search_messages:294.

I have not been able to make a smaller test case at the moment (this
happens with offlineimap updating an maildir and notmuch new run
afterwards + some tagging).

I can work around this by checking for a NULL pointer returned from
notmuch_query_search_threads () and re-open the database
(notmuch_database_close () -> notmuch_database_open ()). But I have no
way of knowing programatically if this really is the error that has
happened. There should be some way of propagating the error
information or (even better for my case; for notmuch to reopen the
database), one option is the Gmime way of passing an pointer to an
error structure that is filled up by the notmuch interface function.

I made some attempts at exposing the ::reopen() function as suggested
by Xapian 
(http://xapian.org/docs/apidoc/html/classXapian_1_1Database.html#af140b1f8d948d13cf7be4a11a7c699a4),
but I end up with other errors afterwards. Possibly from leftover
structures created with the original database handle:

after notmuch_database_reopen (see attached patch for your reference):
  A Xapian exception occurred when reading header: Expected block
24615 to be level 1, not 0
  A Xapian exception occurred when reading header: Error reading block
419480589: got end of file
  A Xapian exception occurred when reading date: Error reading block
419480589: got end of file
  A Xapian exception occurred when reading header: Error reading block
419480589: got end of file


as mentioned, doing a manual _close and _open works. Again, the best
would be a consistent way to really know that this (or something else)
is the error that really happened.

Cheers, Gaute
-- next part --
A non-text attachment was scrubbed...
Name: 0001-lib-expose-XapianDatabae-reopen-through-notmuch_data.patch
Type: text/x-patch
Size: 2141 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20140811/35ba285a/attachment.bin>


Matching on any header line

2014-08-11 Thread David Bremner
Nico Schottelius  writes:

> I have the problem that often To/Cc do not reveal the real destination,
> so I would like to match on X-Original-To: or Delivered-To:
> header lines.
>
> So I was wondering, if there is generic support to match on something
> like "header:x-original-to:this at example.org"?

Such support does not currently exist in notmuch.

d


[PATCH] python: Add binding for notmuch_query_add_tag_exclude

2014-08-11 Thread Thibaut Horel
Implemented as the method `exclude_tag` of the class `Query`. This method takes
one argument, a string containing the name of the tag to exclude.
---
 NEWS  |  5 +
 bindings/python/docs/source/query.rst |  2 ++
 bindings/python/notmuch/query.py  | 15 +++
 3 files changed, 22 insertions(+)

diff --git a/NEWS b/NEWS
index f7aaedf..2d85090 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,11 @@ from the config file.  Use something like:
   ...
 },

+Python Bindings
+---
+
+Add support for `notmuch_query_add_tag_exclude`
+
 Notmuch 0.18.1 (2014-06-25)
 ===

diff --git a/bindings/python/docs/source/query.rst 
b/bindings/python/docs/source/query.rst
index ddfc348..044b573 100644
--- a/bindings/python/docs/source/query.rst
+++ b/bindings/python/docs/source/query.rst
@@ -32,6 +32,8 @@
   :attr:`Query.SORT`) if explicitely specified via
   :meth:`set_sort`. By default it is set to `None`.

+   .. automethod:: exclude_tag
+
.. automethod:: search_threads

.. automethod:: search_messages
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index b11a399..94773ac 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -118,6 +118,21 @@ class Query(object):
 self.sort = sort
 self._set_sort(self._query, sort)

+_exclude_tag = nmlib.notmuch_query_add_tag_exclude
+_exclude_tag.argtypes = [NotmuchQueryP, c_char_p]
+_exclude_tag.resttype = None
+
+def exclude_tag(self, tagname):
+"""Add a tag that will be excluded from the query results by default.
+
+This exclusion will be overridden if this tag appears explicitly in the
+query.
+
+:param tagname: Name of the tag to be excluded
+"""
+self._assert_query_is_initialized()
+self._exclude_tag(self._query, _str(tagname))
+
 """notmuch_query_search_threads"""
 _search_threads = nmlib.notmuch_query_search_threads
 _search_threads.argtypes = [NotmuchQueryP]
-- 
2.0.4



Matching on any header line

2014-08-11 Thread Nico Schottelius
Good morning,

I am using mutt-kz with notmuch as the backend.

I was wondering if it is possible to match on any header line?

I have the problem that often To/Cc do not reveal the real destination,
so I would like to match on X-Original-To: or Delivered-To:
header lines.

So I was wondering, if there is generic support to match on something
like header:x-original-to:t...@example.org?

Cheers,

Nico

p.s.: Please CC on reply, I am not subscribed.

-- 
New PGP key: 659B 0D91 E86E 7E24 FD15  69D0 C729 21A1 293F 2D24
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


DatabaseModifiedErrors causing troubles

2014-08-11 Thread Gaute Hope
Hi,

I've been working on an application that keeps a read-only handle on
the notmuch database open for a long time. In some cases when a new
message is added along with some renames of other messages using
'notmuch new' while the application is running I get an Xapian
exception: DatabaseModifiedError:

  A Xapian exception occurred performing query: The revision being
read has been discarded - you
  should call Xapian::Database::reopen() and retry the operation.

Which seems to be printed from: notmuch_query_search_threads -
notmuch_query_search_messages:294.

I have not been able to make a smaller test case at the moment (this
happens with offlineimap updating an maildir and notmuch new run
afterwards + some tagging).

I can work around this by checking for a NULL pointer returned from
notmuch_query_search_threads () and re-open the database
(notmuch_database_close () - notmuch_database_open ()). But I have no
way of knowing programatically if this really is the error that has
happened. There should be some way of propagating the error
information or (even better for my case; for notmuch to reopen the
database), one option is the Gmime way of passing an pointer to an
error structure that is filled up by the notmuch interface function.

I made some attempts at exposing the ::reopen() function as suggested
by Xapian 
(http://xapian.org/docs/apidoc/html/classXapian_1_1Database.html#af140b1f8d948d13cf7be4a11a7c699a4),
but I end up with other errors afterwards. Possibly from leftover
structures created with the original database handle:

after notmuch_database_reopen (see attached patch for your reference):
  A Xapian exception occurred when reading header: Expected block
24615 to be level 1, not 0
  A Xapian exception occurred when reading header: Error reading block
419480589: got end of file
  A Xapian exception occurred when reading date: Error reading block
419480589: got end of file
  A Xapian exception occurred when reading header: Error reading block
419480589: got end of file


as mentioned, doing a manual _close and _open works. Again, the best
would be a consistent way to really know that this (or something else)
is the error that really happened.

Cheers, Gaute
From 90340fe59d677c989352f08e82f908016c25fafa Mon Sep 17 00:00:00 2001
From: Gaute Hope e...@gaute.vetsj.com
Date: Mon, 11 Aug 2014 14:16:12 +0200
Subject: [PATCH] lib: expose XapianDatabae::reopen() through
 notmuch_database_reopen()

---
 lib/database.cc | 18 ++
 lib/notmuch.h   | 22 ++
 2 files changed, 40 insertions(+)

diff --git a/lib/database.cc b/lib/database.cc
index c760290..80af410 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -778,6 +778,24 @@ notmuch_database_open (const char *path,
 }
 
 notmuch_status_t
+notmuch_database_reopen (notmuch_database_t *notmuch)
+{
+  try {
+notmuch-xapian_db-reopen ();
+
+return NOTMUCH_STATUS_SUCCESS;
+
+  } catch (const Xapian::Error error) {
+	  if (! notmuch-exception_reported) {
+	fprintf (stderr, Error: A Xapian exception occurred while reopening database: %s\n,
+		 error.get_msg().c_str());
+	  }
+
+return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+  }
+}
+
+notmuch_status_t
 notmuch_database_close (notmuch_database_t *notmuch)
 {
 notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 3c5ec98..00950af 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -277,6 +277,28 @@ notmuch_database_open (const char *path,
 		   notmuch_database_t **database);
 
 /**
+ * Reopen the given notmuch database.
+ *
+ * The underlying Xapian database will be re-opened to the latest
+ * available version. It can be used to make sure the latest results
+ * are returned or to recover from an Xapaian::DatabaseModifiedError
+ * which can occur after external database modification.
+ *
+ * Calling notmuch_database_reopen on a database that has been closed
+ * will result in a NOTMUCH_STATUS_XAPAIAN_EXCEPTION.
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Successfully reopened database.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
+ *
+ */
+notmuch_status_t
+notmuch_database_reopen (notmuch_database_t *database);
+
+
+/**
  * Close the given notmuch database.
  *
  * After notmuch_database_close has been called, calls to other
-- 
2.0.3

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


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 v2] Emacs: Add address completion mechanism implemented in elisp

2014-08-11 Thread Michal Sojka
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 core of the new mechanism is the function notmuch-address-harvest
that collects the completion candidates from the notmuch database and
stores them in notmuch-address-completions variable.
notmuch-address-harvest is called on the first entry to message-mode
and runs asychnornously so that the user doesn't have to wait for it
to complete while composing the message. The
notmuch-address-completions variable is used in message-mode as a
source of completion candidates. Currently, there are two ways how the
notmuch-address-completions variable is used.

First, preexisting address completion mechanism is extended to use
notmuch-address-completions in addition to the external command. This
new behavior is configured by setting notmuch-address-command to nil,
which is the new default. Note that this 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.

Second way of using notmuch-address-completions is notmuch-company.el.
This presents the possible completions in a nice popup box after a
short typing delay but requires company-mode to be installed.

Changes from v1:
- Use of notmuch-parser.el instead of the custom parser in the
  original code. The notmuch parser is slightly faster.
- Use of functions in notmuch-query.el instead of functions in the
  original code with almost the same functionality.
- Integrated with existing completion mechanism in notmuch.
- notmuch-company.el was moved from emacs/contrib to emacs and
  no-byte-compile directive was added to it.
- Aligned with notmuch naming conventions.
- Documented bugs found in notmuch-company.el
---
 emacs/Makefile.local |  6 ++-
 emacs/notmuch-address.el | 95 +++-
 emacs/notmuch-company.el | 69 +++
 emacs/notmuch-lib.el |  3 ++
 4 files changed, 163 insertions(+), 10 deletions(-)
 create mode 100644 emacs/notmuch-company.el

diff --git a/emacs/Makefile.local b/emacs/Makefile.local
index c0d6b19..9214d6e 100644
--- a/emacs/Makefile.local
+++ b/emacs/Makefile.local
@@ -18,6 +18,7 @@ emacs_sources := \
$(dir)/notmuch-tag.el \
$(dir)/coolj.el \
$(dir)/notmuch-print.el \
+   $(dir)/notmuch-company.el \
$(dir)/notmuch-version.el
 
 $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
@@ -29,7 +30,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-address.el b/emacs/notmuch-address.el
index fa65cd5..a50f4f4 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,10 @@ to know how address selection is made by default.
   :group 'notmuch-send
   :group 'notmuch-external)
 
+(defvar notmuch-address-completions nil
+  Hash of email addresses for completion during email composition.
+  This variable is set by calling `notmuch-address-harvest'.)
+
 (defun notmuch-address-selection-function (prompt collection initial-input)
   Call (`completing-read'
   PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)
@@ -60,7 +68,16 @@ to know how address