]> granicus.if.org Git - neomutt/commitdiff
add nm_query_type config file option
authorKarel Zak <kzak@redhat.com>
Fri, 7 Sep 2012 07:31:54 +0000 (09:31 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 15:30:06 +0000 (16:30 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
README.notmuch
globals.h
init.h
mutt_notmuch.c

index 77f133d8092d0c9a1798820388acb57d2fd099d5..a38fdeb1912a93b046dadcb55ff325a406d751ff 100644 (file)
@@ -69,7 +69,8 @@ notmuch support for mutt
 
       type=<threads|messages>
 
-         Reads all matching messages or whole-threads. The defauls is 'messages'.
+         Reads all matching messages or whole-threads. The defauls is 'messages'
+         or nm_query_type.
 
 
  * commands:
@@ -158,6 +159,13 @@ notmuch support for mutt
 
      Default is unlimited.
 
+   nm_query_type = <threads|messages>
+
+     This variable specifies notmuch query type, supported types: 'threads' and
+     'messages'.
+
+     Default is 'messages'.
+
    vfolder_format = <string>
 
       This variable allows you to customize the file browser display for virtual
index bf27e1c9b8ca293405b157772bcbe661a7d6c175..e0bf286e42125f06479c76ffae640aa5a99a5caa 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -288,6 +288,7 @@ WHERE char *NotmuchUnreadTag;
 WHERE char *NotmuchHiddenTags;
 WHERE char *VirtFolderFormat;
 WHERE int NotmuchDBLimit;
+WHERE char *NotmuchQueryType;
 #endif
 
 
diff --git a/init.h b/init.h
index 6f3b346ca2ad00bdb1dcca9d03d5085bdc999fb6..f7e7353ad109f177dfe5d6f5ba0ef0fc0604ad35 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1701,6 +1701,11 @@ struct option_t MuttVars[] = {
    ** .pp
    ** This variable specifies the default limit used in notmuch queries.
    */
+  { "nm_query_type", DT_STR, R_NONE, UL &NotmuchQueryType, 0 },
+  /*
+   ** .pp
+   ** This variable specifies the default query type (threads or messages) used in notmuch queries.
+   */
 #endif
   { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
   /*
index 28ad8b4705ad326b3738260447c525e304185d5e..5b190d344bc348c4cd83674dea6491b0ecbd3b7a 100644 (file)
@@ -309,6 +309,22 @@ static struct nm_ctxdata *get_ctxdata(CONTEXT *ctx)
        return NULL;
 }
 
+static int string_to_guery_type(const char *str)
+{
+       if (!str)
+               str = NotmuchQueryType;         /* user's default */
+       if (!str)
+               return NM_QUERY_TYPE_MESGS;     /* hardcoded default */
+
+       if (strcmp(str, "threads") == 0)
+               return NM_QUERY_TYPE_THREADS;
+       else if (strcmp(str, "messages") == 0)
+               return NM_QUERY_TYPE_MESGS;
+
+       mutt_error (_("failed to parse notmuch query type: %s"), str);
+       return NM_QUERY_TYPE_MESGS;
+}
+
 static char *get_query_string(struct nm_ctxdata *data)
 {
        struct uri_tag *item;
@@ -326,18 +342,16 @@ static char *get_query_string(struct nm_ctxdata *data)
                        if (mutt_atoi(item->value, &data->db_limit))
                                mutt_error (_("failed to parse notmuch limit: %s"), item->value);
 
-               } else if (strcmp(item->name, "type") == 0) {
-                       if (strcmp(item->value, "threads") == 0)
-                               data->query_type = NM_QUERY_TYPE_THREADS;
-                       else if (strcmp(item->value, "messages") == 0)
-                               data->query_type = NM_QUERY_TYPE_MESGS;
-                       else
-                               mutt_error (_("failed to parse notmuch query type: %s"), item->value);
+               } else if (strcmp(item->name, "type") == 0)
+                       data->query_type = string_to_guery_type(item->value);
 
-               else if (strcmp(item->name, "query") == 0)
+               else if (strcmp(item->name, "query") == 0)
                        data->db_query = safe_strdup(item->value);
        }
 
+       if (!data->query_type)
+               data->query_type = string_to_guery_type(NULL);
+
        dprint(2, (debugfile, "nm: query '%s'\n", data->db_query));
 
        return data->db_query;