[PATCH] completion: update bash completion

2013-11-06 Thread Jani Nikula
Update bash completion to cover new commands and options:

notmuch compact --quiet --backup=DIR
notmuch count --output=files --batch --input=FILE
notmuch insert --folder=DIR --create-folder
notmuch search --exclude=all --duplicate=N
notmuch show --include-html
notmuch tag --batch --input=FILE --remove-all

---

This logically depends on id:cover.1383481295.git.jani at nikula.org
which adds --quiet and --backup=DIR parameters to compact.
---
 completion/notmuch-completion.bash | 89 +++---
 1 file changed, 82 insertions(+), 7 deletions(-)

diff --git a/completion/notmuch-completion.bash 
b/completion/notmuch-completion.bash
index 7bd7745..04324bb 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -59,6 +59,29 @@ _notmuch_search_terms()
 __ltrim_colon_completions "${cur}"
 }

+_notmuch_compact()
+{
+local cur prev words cword split
+_init_completion -s || return
+
+$split &&
+case "${prev}" in
+   --backup)
+   _filedir
+   return
+   ;;
+esac
+
+! $split &&
+case "${cur}" in
+   -*)
+   local options="--backup= --quiet"
+   compopt -o nospace
+   COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
+   ;;
+esac
+}
+
 _notmuch_config()
 {
 local cur prev words cword split
@@ -89,19 +112,23 @@ _notmuch_count()
 $split &&
 case "${prev}" in
--output)
-   COMPREPLY=( $( compgen -W "messages threads" -- "${cur}" ) )
+   COMPREPLY=( $( compgen -W "messages threads files" -- "${cur}" ) )
return
;;
--exclude)
COMPREPLY=( $( compgen -W "true false" -- "${cur}" ) )
return
;;
+   --input)
+   _filedir
+   return
+   ;;
 esac

 ! $split &&
 case "${cur}" in
-*)
-   local options="--output= --exclude="
+   local options="--output= --exclude= --batch --input="
compopt -o nospace
COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
;;
@@ -141,6 +168,39 @@ _notmuch_dump()
 esac
 }

+_notmuch_insert()
+{
+local cur prev words cword split
+# handle tags with colons and equal signs
+_init_completion -s -n := || return
+
+$split &&
+case "${prev}" in
+   --folder)
+   _filedir
+   return
+   ;;
+esac
+
+! $split &&
+case "${cur}" in
+   --*)
+   local options="--create-folder --folder="
+   compopt -o nospace
+   COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
+   return
+   ;;
+   +*)
+   COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" 
-- ${cur##+}) )
+   ;;
+   -*)
+   COMPREPLY=( $(compgen -P "-" -W "`notmuch search --output=tags \*`" 
-- ${cur##-}) )
+   ;;
+esac
+# handle tags with colons
+__ltrim_colon_completions "${cur}"
+}
+
 _notmuch_new()
 {
 local cur prev words cword split
@@ -231,7 +291,7 @@ _notmuch_search()
return
;;
--exclude)
-   COMPREPLY=( $( compgen -W "true false flag" -- "${cur}" ) )
+   COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
return
;;
 esac
@@ -239,7 +299,7 @@ _notmuch_search()
 ! $split &&
 case "${cur}" in
-*)
-   local options="--format= --output= --sort= --offset= --limit= 
--exclude="
+   local options="--format= --output= --sort= --offset= --limit= 
--exclude= --duplicate="
compopt -o nospace
COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
;;
@@ -273,7 +333,7 @@ _notmuch_show()
 ! $split &&
 case "${cur}" in
-*)
-   local options="--entire-thread= --format= --exclude= --body= 
--format-version= --part= --verify --decrypt"
+   local options="--entire-thread= --format= --exclude= --body= 
--format-version= --part= --verify --decrypt --include-html"
compopt -o nospace
COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
;;
@@ -287,9 +347,24 @@ _notmuch_tag()
 {
 local cur prev words cword split
 # handle tags with colons and equal signs
-_init_completion -n := || return
+_init_completion -s -n := || return
+
+$split &&
+case "${prev}" in
+   --input)
+   _filedir
+   return
+   ;;
+esac

+! $split &&
 case "${cur}" in
+   --*)
+   local options="--batch --input= --remove-all"
+   compopt -o nospace
+   COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
+   return
+   ;;
+*)
COMPREPLY=( $(compgen -P "+" -W "`notmuch search --output=tags \*`" 
-- ${cur##+}) )
;;
@@ -307,7 +382,7 @@ _notmuch_tag()

 _notmuch()
 {
-local _notmuch_commands="config count dump help new reply restore search 

[PATCH] lib: add library version check macro

2013-11-06 Thread Jani Nikula
There have been some plans for making build incompatible changes to
the library API. This is inconvenient, but it is much more so without
a way to easily conditional build against multiple versions of
notmuch.

The macro has been lifted from glib.
---
 lib/notmuch.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 9dab555..d109a2c 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -41,6 +41,30 @@ NOTMUCH_BEGIN_DECLS
 #define TRUE 1
 #endif

+#define NOTMUCH_MAJOR_VERSION  0
+#define NOTMUCH_MINOR_VERSION  17
+#define NOTMUCH_MICRO_VERSION  0
+
+/*
+ * Check the version of the notmuch library being compiled against.
+ *
+ * Return true if the library being compiled against is of the
+ * specified version or above. For example:
+ *
+ * #if NOTMUCH_CHECK_VERSION(0, 18, 0)
+ * (code requiring notmuch 0.18 or above)
+ * #endif
+ *
+ * NOTMUCH_CHECK_VERSION has been defined since version 0.17.0; you
+ * can use #if !defined(NOTMUCH_CHECK_VERSION) to check for versions
+ * prior to that.
+ */
+#define NOTMUCH_CHECK_VERSION (major, minor, micro)\
+(NOTMUCH_MAJOR_VERSION > (major) ||
\
+ (NOTMUCH_MAJOR_VERSION == (major) && NOTMUCH_MINOR_VERSION > (minor)) || \
+ (NOTMUCH_MAJOR_VERSION == (major) && NOTMUCH_MINOR_VERSION == (minor) && \
+  NOTMUCH_MICRO_VERSION >= (micro)))
+
 typedef int notmuch_bool_t;

 /* Status codes used for the return values of most functions.
-- 
1.8.4.rc3



[RFC PATCH 2/2] lib: modify notmuch.h for automatic document generation

2013-11-06 Thread Jani Nikula
Minimal changes to produce a sensible result.
---
 lib/notmuch.h | 426 +++---
 1 file changed, 289 insertions(+), 137 deletions(-)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 9dab555..6d91b17 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -18,9 +18,19 @@
  * Author: Carl Worth 
  */

+/**
+ * @defgroup notmuch The notmuch API
+ *
+ * Not much of an email library, (just index and search)
+ *
+ * @{
+ */
+
 #ifndef NOTMUCH_H
 #define NOTMUCH_H

+#ifndef __DOXYGEN__
+
 #ifdef  __cplusplus
 # define NOTMUCH_BEGIN_DECLS  extern "C" {
 # define NOTMUCH_END_DECLS}
@@ -33,6 +43,8 @@ NOTMUCH_BEGIN_DECLS

 #include 

+#endif /* __DOXYGEN__ */
+
 #ifndef FALSE
 #define FALSE 0
 #endif
@@ -41,72 +53,87 @@ NOTMUCH_BEGIN_DECLS
 #define TRUE 1
 #endif

+/**
+ * Notmuch boolean type.
+ */
 typedef int notmuch_bool_t;

-/* Status codes used for the return values of most functions.
+/**
+ * Status codes used for the return values of most functions.
  *
  * A zero value (NOTMUCH_STATUS_SUCCESS) indicates that the function
- * completed without error. Any other value indicates an error as
- * follows:
- *
- * NOTMUCH_STATUS_SUCCESS: No error occurred.
- *
- * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory
- *
- * XXX: We don't really want to expose this lame XAPIAN_EXCEPTION
- * value. Instead we should map to things like DATABASE_LOCKED or
- * whatever.
- *
- * NOTMUCH_STATUS_READ_ONLY_DATABASE: An attempt was made to write to
- * a database opened in read-only mode.
+ * completed without error. Any other value indicates an error.
  *
- * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
- *
- * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to read or
- * write to a file (this could be file not found, permission
- * denied, etc.)
- *
- * NOTMUCH_STATUS_FILE_NOT_EMAIL: A file was presented that doesn't
- * appear to be an email message.
- *
- * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: A file contains a message ID
- * that is identical to a message already in the database.
- *
- * NOTMUCH_STATUS_NULL_POINTER: The user erroneously passed a NULL
- * pointer to a notmuch function.
- *
- * NOTMUCH_STATUS_TAG_TOO_LONG: A tag value is too long (exceeds
- * NOTMUCH_TAG_MAX)
- *
- * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: The notmuch_message_thaw
- * function has been called more times than notmuch_message_freeze.
- *
- * NOTMUCH_STATUS_UNBALANCED_ATOMIC: notmuch_database_end_atomic has
- * been called more times than notmuch_database_begin_atomic.
- *
- * And finally:
- *
- * NOTMUCH_STATUS_LAST_STATUS: Not an actual status value. Just a way
- * to find out how many valid status values there are.
  */
 typedef enum _notmuch_status {
+/**
+ * No error occurred.
+ */
 NOTMUCH_STATUS_SUCCESS = 0,
+/**
+ * Out of memory.
+ */
 NOTMUCH_STATUS_OUT_OF_MEMORY,
+/**
+ * An attempt was made to write to a database opened in read-only
+ * mode.
+ */
 NOTMUCH_STATUS_READ_ONLY_DATABASE,
+/**
+ * A Xapian exception occurred.
+ */
 NOTMUCH_STATUS_XAPIAN_EXCEPTION,
+/**
+ * An error occurred trying to read or write to a file (this could
+ * be file not found, permission denied, etc.)
+ *
+ * @todo We don't really want to expose this lame XAPIAN_EXCEPTION
+ * value. Instead we should map to things like DATABASE_LOCKED or
+ * whatever.
+ */
 NOTMUCH_STATUS_FILE_ERROR,
+/**
+ * A file was presented that doesn't appear to be an email
+ * message.
+ */
 NOTMUCH_STATUS_FILE_NOT_EMAIL,
+/**
+ * A file contains a message ID that is identical to a message
+ * already in the database.
+ */
 NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID,
+/**
+ * The user erroneously passed a NULL pointer to a notmuch
+ * function.
+ */
 NOTMUCH_STATUS_NULL_POINTER,
+/**
+ * A tag value is too long (exceeds NOTMUCH_TAG_MAX).
+ */
 NOTMUCH_STATUS_TAG_TOO_LONG,
+/**
+ * The notmuch_message_thaw function has been called more times
+ * than notmuch_message_freeze.
+ */
 NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
+/**
+ * notmuch_database_end_atomic has been called more times than
+ * notmuch_database_begin_atomic.
+ */
 NOTMUCH_STATUS_UNBALANCED_ATOMIC,
+/**
+ * The operation is not supported.
+ */
 NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
-
+/**
+ * Not an actual status value. Just a way to find out how many
+ * valid status values there are.
+ */
 NOTMUCH_STATUS_LAST_STATUS
 } notmuch_status_t;

-/* Get a string representation of a notmuch_status_t value.
+/**
+ * Get a string representation of a notmuch_status_t value.
  *
  * The result is read-only.
  */
@@ -125,7 +152,8 @@ typedef struct _notmuch_tags notmuch_tags_t;
 typedef struct _notmuch_directory notmuch_directory_t;
 typedef struct _notmuch_filenames notmuch_filenames_t;


[RFC PATCH 1/2] devel: add doxygen configuration file

2013-11-06 Thread Jani Nikula
To generate library man page from lib/notmuch.h using

$ doxygen devel/doxygen.cfg
---
 devel/doxygen.cfg | 1890 +
 1 file changed, 1890 insertions(+)
 create mode 100644 devel/doxygen.cfg

diff --git a/devel/doxygen.cfg b/devel/doxygen.cfg
new file mode 100644
index 000..e44305b
--- /dev/null
+++ b/devel/doxygen.cfg
@@ -0,0 +1,1890 @@
+# Doxyfile 1.8.4
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed
+# in front of the TAG it is preceding .
+# All text after a hash (#) is considered a comment and will be ignored.
+# The format is:
+#   TAG = value [value, ...]
+# For lists items can also be appended using:
+#   TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ").
+
+#---
+# Project related configuration options
+#---
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING  = UTF-8
+
+# The PROJECT_NAME tag is a single word (or sequence of words) that should
+# identify the project. Note that if you do not use Doxywizard you need
+# to put quotes around the project name if it contains spaces.
+
+PROJECT_NAME   = "Notmuch 0.17"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER =
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer
+# a quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF  =
+
+# With the PROJECT_LOGO tag one can specify an logo or icon that is
+# included in the documentation. The maximum height of the logo should not
+# exceed 55 pixels and the maximum width should not exceed 200 pixels.
+# Doxygen will copy the logo to the output directory.
+
+PROJECT_LOGO   =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY   =
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Latvian, Lithuanian, Norwegian, Macedonian,
+# Persian, Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic,
+# Slovak, Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE= English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC  = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed 
description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF   = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the 

[RFC PATCH 0/2] library reference man page

2013-11-06 Thread Jani Nikula
These two patches add a doxygen configuration file and minimal changes
to lib/notmuch.h to produce man/man3/notmuch.3 library reference.

Apply patches, and run
 $ doxygen devel/doxygen.cfg
 $ man man/man3/notmuch.3

There's still plenty to do, but perhaps we could get started with
merging this? There's no harm done, and would help collaboration on
this.

TODO:

* make this part of the build/install process
* check version in release checks
* figure out how to *not* create a file list man page
* upload the man page to the web site
* generate html pages too, and upload to web site also
* start using doxygen/javadoc tags to produce nicer output


Cheers,
Jani.


Jani Nikula (2):
  devel: add doxygen configuration file
  lib: modify notmuch.h for automatic document generation

 devel/doxygen.cfg | 1890 +
 lib/notmuch.h |  426 
 2 files changed, 2179 insertions(+), 137 deletions(-)
 create mode 100644 devel/doxygen.cfg

-- 
1.8.4.rc3



[PATCH] lib: add library version check macro

2013-11-06 Thread David Bremner
Jani Nikula  writes:

> There have been some plans for making build incompatible changes to
> the library API. This is inconvenient, but it is much more so without
> a way to easily conditional build against multiple versions of
> notmuch.
>
> The macro has been lifted from glib.

This seems fine to me. I even thought about the licensing for these 3
lines of code ;).

d


[PATCH 2/2] man: document notmuch compact --quiet and --backup=DIRECTORY options

2013-11-06 Thread Jani Nikula
---

v2: --verbose -> --quiet
---
 man/man1/notmuch-compact.1 | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/man/man1/notmuch-compact.1 b/man/man1/notmuch-compact.1
index 1aeed22..0c95873 100644
--- a/man/man1/notmuch-compact.1
+++ b/man/man1/notmuch-compact.1
@@ -4,6 +4,8 @@ notmuch-compact \- compact the notmuch database
 .SH SYNOPSIS

 .B notmuch compact
+.RI "[ --quiet ]"
+.RI "[ --backup=<" directory "> ]"

 .SH DESCRIPTION

@@ -14,11 +16,35 @@ the space required by the database and improve lookup 
performance.

 The compacted database is built in a temporary directory and is later
 moved into the place of the origin database. The original uncompacted
-database is preserved to be deleted by the user as desired.
+database is discarded, unless the
+.BR "\-\-backup=" 
+option is used.

 Note that the database write lock will be held during the compaction
 process (which may be quite long) to protect data integrity.

+Supported options for
+.B compact
+include
+
+.RS 4
+.TP 4
+.BR "\-\-backup=" 
+
+Save the current database to the given directory before replacing it
+with the compacted database. The backup directory must not exist and
+it must reside on the same mounted filesystem as the current database.
+
+.RE
+
+.RS 4
+.TP 4
+.BR \-\-quiet
+
+Do not report database compaction progress to stdout.
+
+.RE
+
 .RE
 .SH ENVIRONMENT
 The following environment variables can be used to control the
-- 
1.8.4.rc3



[PATCH 1/2] cli: add compact --quiet option and silence output with it

2013-11-06 Thread Jani Nikula
Provide a way to silence the output.

---

v2: --verbose -> --quiet
---
 notmuch-compact.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/notmuch-compact.c b/notmuch-compact.c
index 359acfc..8022dfe 100644
--- a/notmuch-compact.c
+++ b/notmuch-compact.c
@@ -32,27 +32,33 @@ notmuch_compact_command (notmuch_config_t *config, int 
argc, char *argv[])
 const char *path = notmuch_config_get_database_path (config);
 const char *backup_path = NULL;
 notmuch_status_t ret;
+notmuch_bool_t quiet;
 int opt_index;

 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_STRING, _path, "backup", 0, 0 },
+   { NOTMUCH_OPT_BOOLEAN,  , "quiet", 'q', 0 },
 };

 opt_index = parse_arguments (argc, argv, options, 1);
 if (opt_index < 0)
return 1;

-printf ("Compacting database...\n");
-ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL);
+if (! quiet)
+   printf ("Compacting database...\n");
+ret = notmuch_database_compact (path, backup_path,
+   quiet ? NULL : status_update_cb, NULL);
 if (ret) {
fprintf (stderr, "Compaction failed: %s\n", 
notmuch_status_to_string(ret));
return 1;
 }

-if (backup_path)
-   printf ("The old database has been moved to %s.\n", backup_path);
+if (! quiet) {
+   if (backup_path)
+   printf ("The old database has been moved to %s.\n", backup_path);

-printf ("Done.\n");
+   printf ("Done.\n");
+}

 return 0;
 }
-- 
1.8.4.rc3



[PATCH v2 03/11] lib: check talloc success in compact

2013-11-06 Thread David Bremner
Jani Nikula  writes:

> In line with the allocation checks all around.

Pushed the first three. 

d


[PATCH 1/2] cli: add compact --quiet option and silence output with it

2013-11-06 Thread Jani Nikula
Provide a way to silence the output.

---

v2: --verbose - --quiet
---
 notmuch-compact.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/notmuch-compact.c b/notmuch-compact.c
index 359acfc..8022dfe 100644
--- a/notmuch-compact.c
+++ b/notmuch-compact.c
@@ -32,27 +32,33 @@ notmuch_compact_command (notmuch_config_t *config, int 
argc, char *argv[])
 const char *path = notmuch_config_get_database_path (config);
 const char *backup_path = NULL;
 notmuch_status_t ret;
+notmuch_bool_t quiet;
 int opt_index;
 
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_STRING, backup_path, backup, 0, 0 },
+   { NOTMUCH_OPT_BOOLEAN,  quiet, quiet, 'q', 0 },
 };
 
 opt_index = parse_arguments (argc, argv, options, 1);
 if (opt_index  0)
return 1;
 
-printf (Compacting database...\n);
-ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL);
+if (! quiet)
+   printf (Compacting database...\n);
+ret = notmuch_database_compact (path, backup_path,
+   quiet ? NULL : status_update_cb, NULL);
 if (ret) {
fprintf (stderr, Compaction failed: %s\n, 
notmuch_status_to_string(ret));
return 1;
 }
 
-if (backup_path)
-   printf (The old database has been moved to %s.\n, backup_path);
+if (! quiet) {
+   if (backup_path)
+   printf (The old database has been moved to %s.\n, backup_path);
 
-printf (Done.\n);
+   printf (Done.\n);
+}
 
 return 0;
 }
-- 
1.8.4.rc3

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


[RFC PATCH 2/2] lib: modify notmuch.h for automatic document generation

2013-11-06 Thread Jani Nikula
Minimal changes to produce a sensible result.
---
 lib/notmuch.h | 426 +++---
 1 file changed, 289 insertions(+), 137 deletions(-)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 9dab555..6d91b17 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -18,9 +18,19 @@
  * Author: Carl Worth cwo...@cworth.org
  */
 
+/**
+ * @defgroup notmuch The notmuch API
+ *
+ * Not much of an email library, (just index and search)
+ *
+ * @{
+ */
+
 #ifndef NOTMUCH_H
 #define NOTMUCH_H
 
+#ifndef __DOXYGEN__
+
 #ifdef  __cplusplus
 # define NOTMUCH_BEGIN_DECLS  extern C {
 # define NOTMUCH_END_DECLS}
@@ -33,6 +43,8 @@ NOTMUCH_BEGIN_DECLS
 
 #include time.h
 
+#endif /* __DOXYGEN__ */
+
 #ifndef FALSE
 #define FALSE 0
 #endif
@@ -41,72 +53,87 @@ NOTMUCH_BEGIN_DECLS
 #define TRUE 1
 #endif
 
+/**
+ * Notmuch boolean type.
+ */
 typedef int notmuch_bool_t;
 
-/* Status codes used for the return values of most functions.
+/**
+ * Status codes used for the return values of most functions.
  *
  * A zero value (NOTMUCH_STATUS_SUCCESS) indicates that the function
- * completed without error. Any other value indicates an error as
- * follows:
- *
- * NOTMUCH_STATUS_SUCCESS: No error occurred.
- *
- * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory
- *
- * XXX: We don't really want to expose this lame XAPIAN_EXCEPTION
- * value. Instead we should map to things like DATABASE_LOCKED or
- * whatever.
- *
- * NOTMUCH_STATUS_READ_ONLY_DATABASE: An attempt was made to write to
- * a database opened in read-only mode.
+ * completed without error. Any other value indicates an error.
  *
- * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
- *
- * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to read or
- * write to a file (this could be file not found, permission
- * denied, etc.)
- *
- * NOTMUCH_STATUS_FILE_NOT_EMAIL: A file was presented that doesn't
- * appear to be an email message.
- *
- * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: A file contains a message ID
- * that is identical to a message already in the database.
- *
- * NOTMUCH_STATUS_NULL_POINTER: The user erroneously passed a NULL
- * pointer to a notmuch function.
- *
- * NOTMUCH_STATUS_TAG_TOO_LONG: A tag value is too long (exceeds
- * NOTMUCH_TAG_MAX)
- *
- * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: The notmuch_message_thaw
- * function has been called more times than notmuch_message_freeze.
- *
- * NOTMUCH_STATUS_UNBALANCED_ATOMIC: notmuch_database_end_atomic has
- * been called more times than notmuch_database_begin_atomic.
- *
- * And finally:
- *
- * NOTMUCH_STATUS_LAST_STATUS: Not an actual status value. Just a way
- * to find out how many valid status values there are.
  */
 typedef enum _notmuch_status {
+/**
+ * No error occurred.
+ */
 NOTMUCH_STATUS_SUCCESS = 0,
+/**
+ * Out of memory.
+ */
 NOTMUCH_STATUS_OUT_OF_MEMORY,
+/**
+ * An attempt was made to write to a database opened in read-only
+ * mode.
+ */
 NOTMUCH_STATUS_READ_ONLY_DATABASE,
+/**
+ * A Xapian exception occurred.
+ */
 NOTMUCH_STATUS_XAPIAN_EXCEPTION,
+/**
+ * An error occurred trying to read or write to a file (this could
+ * be file not found, permission denied, etc.)
+ *
+ * @todo We don't really want to expose this lame XAPIAN_EXCEPTION
+ * value. Instead we should map to things like DATABASE_LOCKED or
+ * whatever.
+ */
 NOTMUCH_STATUS_FILE_ERROR,
+/**
+ * A file was presented that doesn't appear to be an email
+ * message.
+ */
 NOTMUCH_STATUS_FILE_NOT_EMAIL,
+/**
+ * A file contains a message ID that is identical to a message
+ * already in the database.
+ */
 NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID,
+/**
+ * The user erroneously passed a NULL pointer to a notmuch
+ * function.
+ */
 NOTMUCH_STATUS_NULL_POINTER,
+/**
+ * A tag value is too long (exceeds NOTMUCH_TAG_MAX).
+ */
 NOTMUCH_STATUS_TAG_TOO_LONG,
+/**
+ * The notmuch_message_thaw function has been called more times
+ * than notmuch_message_freeze.
+ */
 NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
+/**
+ * notmuch_database_end_atomic has been called more times than
+ * notmuch_database_begin_atomic.
+ */
 NOTMUCH_STATUS_UNBALANCED_ATOMIC,
+/**
+ * The operation is not supported.
+ */
 NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
-
+/**
+ * Not an actual status value. Just a way to find out how many
+ * valid status values there are.
+ */
 NOTMUCH_STATUS_LAST_STATUS
 } notmuch_status_t;
 
-/* Get a string representation of a notmuch_status_t value.
+/**
+ * Get a string representation of a notmuch_status_t value.
  *
  * The result is read-only.
  */
@@ -125,7 +152,8 @@ typedef struct _notmuch_tags notmuch_tags_t;
 typedef struct _notmuch_directory notmuch_directory_t;
 typedef struct 

[PATCH 2/2] man: document notmuch compact --quiet and --backup=DIRECTORY options

2013-11-06 Thread Jani Nikula
---

v2: --verbose - --quiet
---
 man/man1/notmuch-compact.1 | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/man/man1/notmuch-compact.1 b/man/man1/notmuch-compact.1
index 1aeed22..0c95873 100644
--- a/man/man1/notmuch-compact.1
+++ b/man/man1/notmuch-compact.1
@@ -4,6 +4,8 @@ notmuch-compact \- compact the notmuch database
 .SH SYNOPSIS
 
 .B notmuch compact
+.RI [ --quiet ]
+.RI [ --backup= directory  ]
 
 .SH DESCRIPTION
 
@@ -14,11 +16,35 @@ the space required by the database and improve lookup 
performance.
 
 The compacted database is built in a temporary directory and is later
 moved into the place of the origin database. The original uncompacted
-database is preserved to be deleted by the user as desired.
+database is discarded, unless the
+.BR \-\-backup= directory
+option is used.
 
 Note that the database write lock will be held during the compaction
 process (which may be quite long) to protect data integrity.
 
+Supported options for
+.B compact
+include
+
+.RS 4
+.TP 4
+.BR \-\-backup= directory
+
+Save the current database to the given directory before replacing it
+with the compacted database. The backup directory must not exist and
+it must reside on the same mounted filesystem as the current database.
+
+.RE
+
+.RS 4
+.TP 4
+.BR \-\-quiet
+
+Do not report database compaction progress to stdout.
+
+.RE
+
 .RE
 .SH ENVIRONMENT
 The following environment variables can be used to control the
-- 
1.8.4.rc3

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


[PATCH] lib: add library version check macro

2013-11-06 Thread Jani Nikula
There have been some plans for making build incompatible changes to
the library API. This is inconvenient, but it is much more so without
a way to easily conditional build against multiple versions of
notmuch.

The macro has been lifted from glib.
---
 lib/notmuch.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 9dab555..d109a2c 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -41,6 +41,30 @@ NOTMUCH_BEGIN_DECLS
 #define TRUE 1
 #endif
 
+#define NOTMUCH_MAJOR_VERSION  0
+#define NOTMUCH_MINOR_VERSION  17
+#define NOTMUCH_MICRO_VERSION  0
+
+/*
+ * Check the version of the notmuch library being compiled against.
+ *
+ * Return true if the library being compiled against is of the
+ * specified version or above. For example:
+ *
+ * #if NOTMUCH_CHECK_VERSION(0, 18, 0)
+ * (code requiring notmuch 0.18 or above)
+ * #endif
+ *
+ * NOTMUCH_CHECK_VERSION has been defined since version 0.17.0; you
+ * can use #if !defined(NOTMUCH_CHECK_VERSION) to check for versions
+ * prior to that.
+ */
+#define NOTMUCH_CHECK_VERSION (major, minor, micro)\
+(NOTMUCH_MAJOR_VERSION  (major) ||
\
+ (NOTMUCH_MAJOR_VERSION == (major)  NOTMUCH_MINOR_VERSION  (minor)) || \
+ (NOTMUCH_MAJOR_VERSION == (major)  NOTMUCH_MINOR_VERSION == (minor)  \
+  NOTMUCH_MICRO_VERSION = (micro)))
+
 typedef int notmuch_bool_t;
 
 /* Status codes used for the return values of most functions.
-- 
1.8.4.rc3

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


[PATCH] completion: update bash completion

2013-11-06 Thread Jani Nikula
Update bash completion to cover new commands and options:

notmuch compact --quiet --backup=DIR
notmuch count --output=files --batch --input=FILE
notmuch insert --folder=DIR --create-folder
notmuch search --exclude=all --duplicate=N
notmuch show --include-html
notmuch tag --batch --input=FILE --remove-all

---

This logically depends on id:cover.1383481295.git.j...@nikula.org
which adds --quiet and --backup=DIR parameters to compact.
---
 completion/notmuch-completion.bash | 89 +++---
 1 file changed, 82 insertions(+), 7 deletions(-)

diff --git a/completion/notmuch-completion.bash 
b/completion/notmuch-completion.bash
index 7bd7745..04324bb 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -59,6 +59,29 @@ _notmuch_search_terms()
 __ltrim_colon_completions ${cur}
 }
 
+_notmuch_compact()
+{
+local cur prev words cword split
+_init_completion -s || return
+
+$split 
+case ${prev} in
+   --backup)
+   _filedir
+   return
+   ;;
+esac
+
+! $split 
+case ${cur} in
+   -*)
+   local options=--backup= --quiet
+   compopt -o nospace
+   COMPREPLY=( $(compgen -W $options -- ${cur}) )
+   ;;
+esac
+}
+
 _notmuch_config()
 {
 local cur prev words cword split
@@ -89,19 +112,23 @@ _notmuch_count()
 $split 
 case ${prev} in
--output)
-   COMPREPLY=( $( compgen -W messages threads -- ${cur} ) )
+   COMPREPLY=( $( compgen -W messages threads files -- ${cur} ) )
return
;;
--exclude)
COMPREPLY=( $( compgen -W true false -- ${cur} ) )
return
;;
+   --input)
+   _filedir
+   return
+   ;;
 esac
 
 ! $split 
 case ${cur} in
-*)
-   local options=--output= --exclude=
+   local options=--output= --exclude= --batch --input=
compopt -o nospace
COMPREPLY=( $(compgen -W $options -- ${cur}) )
;;
@@ -141,6 +168,39 @@ _notmuch_dump()
 esac
 }
 
+_notmuch_insert()
+{
+local cur prev words cword split
+# handle tags with colons and equal signs
+_init_completion -s -n := || return
+
+$split 
+case ${prev} in
+   --folder)
+   _filedir
+   return
+   ;;
+esac
+
+! $split 
+case ${cur} in
+   --*)
+   local options=--create-folder --folder=
+   compopt -o nospace
+   COMPREPLY=( $(compgen -W $options -- ${cur}) )
+   return
+   ;;
+   +*)
+   COMPREPLY=( $(compgen -P + -W `notmuch search --output=tags \*` 
-- ${cur##+}) )
+   ;;
+   -*)
+   COMPREPLY=( $(compgen -P - -W `notmuch search --output=tags \*` 
-- ${cur##-}) )
+   ;;
+esac
+# handle tags with colons
+__ltrim_colon_completions ${cur}
+}
+
 _notmuch_new()
 {
 local cur prev words cword split
@@ -231,7 +291,7 @@ _notmuch_search()
return
;;
--exclude)
-   COMPREPLY=( $( compgen -W true false flag -- ${cur} ) )
+   COMPREPLY=( $( compgen -W true false flag all -- ${cur} ) )
return
;;
 esac
@@ -239,7 +299,7 @@ _notmuch_search()
 ! $split 
 case ${cur} in
-*)
-   local options=--format= --output= --sort= --offset= --limit= 
--exclude=
+   local options=--format= --output= --sort= --offset= --limit= 
--exclude= --duplicate=
compopt -o nospace
COMPREPLY=( $(compgen -W $options -- ${cur}) )
;;
@@ -273,7 +333,7 @@ _notmuch_show()
 ! $split 
 case ${cur} in
-*)
-   local options=--entire-thread= --format= --exclude= --body= 
--format-version= --part= --verify --decrypt
+   local options=--entire-thread= --format= --exclude= --body= 
--format-version= --part= --verify --decrypt --include-html
compopt -o nospace
COMPREPLY=( $(compgen -W $options -- ${cur}) )
;;
@@ -287,9 +347,24 @@ _notmuch_tag()
 {
 local cur prev words cword split
 # handle tags with colons and equal signs
-_init_completion -n := || return
+_init_completion -s -n := || return
+
+$split 
+case ${prev} in
+   --input)
+   _filedir
+   return
+   ;;
+esac
 
+! $split 
 case ${cur} in
+   --*)
+   local options=--batch --input= --remove-all
+   compopt -o nospace
+   COMPREPLY=( $(compgen -W $options -- ${cur}) )
+   return
+   ;;
+*)
COMPREPLY=( $(compgen -P + -W `notmuch search --output=tags \*` 
-- ${cur##+}) )
;;
@@ -307,7 +382,7 @@ _notmuch_tag()
 
 _notmuch()
 {
-local _notmuch_commands=config count dump help new reply restore search 
setup show tag
+local _notmuch_commands=compact config count dump help insert new reply 
restore search 

Re: [PATCH v2 03/11] lib: check talloc success in compact

2013-11-06 Thread David Bremner
Jani Nikula j...@nikula.org writes:

 In line with the allocation checks all around.

Pushed the first three. 

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


Re: [PATCH] lib: add library version check macro

2013-11-06 Thread David Bremner
Jani Nikula j...@nikula.org writes:

 There have been some plans for making build incompatible changes to
 the library API. This is inconvenient, but it is much more so without
 a way to easily conditional build against multiple versions of
 notmuch.

 The macro has been lifted from glib.

This seems fine to me. I even thought about the licensing for these 3
lines of code ;).

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