[PATCH] News for new 'previous' behavior
[notmuch-archives.git] / 6b / 331fde5db9f4b3b28f77f076d3632c18d42cc3
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 935FF429E32\r
6         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:50 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id KA0jZ0XY482X for <notmuch@notmuchmail.org>;\r
17         Fri, 28 Oct 2011 13:59:49 -0700 (PDT)\r
18 Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
19         [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 5A918429E21\r
22         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:47 -0700 (PDT)\r
23 Received: by mail-fx0-f53.google.com with SMTP id i28so4419077faa.26\r
24         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:47 -0700 (PDT)\r
25 Received: by 10.223.92.135 with SMTP id r7mr8801871fam.35.1319835587101;\r
26         Fri, 28 Oct 2011 13:59:47 -0700 (PDT)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id j5sm19444105faf.14.2011.10.28.13.59.45\r
30         (version=SSLv3 cipher=OTHER); Fri, 28 Oct 2011 13:59:46 -0700 (PDT)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [RFC PATCH 2/3] cli: add support for limiting the number of search\r
34         results\r
35 Date: Fri, 28 Oct 2011 23:59:30 +0300\r
36 Message-Id:\r
37  <f16c7983a8a639ea2ed1178a3190afb9620153e2.1319833617.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <cover.1319833617.git.jani@nikula.org>\r
40 References: <cover.1319833617.git.jani@nikula.org>\r
41 In-Reply-To: <cover.1319833617.git.jani@nikula.org>\r
42 References: <cover.1319833617.git.jani@nikula.org>\r
43 Cc: amdragon@mit.edu\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Fri, 28 Oct 2011 20:59:51 -0000\r
57 \r
58 Add command line parameter --maxitems=N to notmuch search to limit the\r
59 number of displayed messages to N.\r
60 \r
61 These two are equal:\r
62 \r
63 $ notmuch search --output=messages --sort=newest-first --maxitems=10 SEARCH\r
64 $ notmuch search --output=messages --sort=newest-first SEARCH | head\r
65 \r
66 As are these:\r
67 \r
68 $ notmuch search --output=messages --sort=oldest-first --maxitems=10 SEARCH\r
69 $ notmuch search --output=messages --sort=oldest-first SEARCH | tail\r
70 \r
71 Note that N refers to the maximum amount of messages, even for\r
72 --output=threads.\r
73 \r
74 Signed-off-by: Jani Nikula <jani@nikula.org>\r
75 ---\r
76  notmuch-search.c |   10 ++++++++++\r
77  1 files changed, 10 insertions(+), 0 deletions(-)\r
78 \r
79 diff --git a/notmuch-search.c b/notmuch-search.c\r
80 index 6f04d9a..a3a6475 100644\r
81 --- a/notmuch-search.c\r
82 +++ b/notmuch-search.c\r
83 @@ -394,6 +394,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
84      const search_format_t *format = &format_text;\r
85      int i, ret;\r
86      output_t output = OUTPUT_SUMMARY;\r
87 +    unsigned int maxitems = 0;\r
88  \r
89      argc--; argv++; /* skip subcommand argument */\r
90  \r
91 @@ -412,6 +413,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
92                 fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
93                 return 1;\r
94             }\r
95 +       } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) {\r
96 +           const char *p;\r
97 +           opt = argv[i] + sizeof ("--maxitems=") - 1;\r
98 +           maxitems = strtoul(opt, &p, 10);\r
99 +           if (*opt == '\0' || p == opt || *p != '\0') {\r
100 +               fprintf (stderr, "Invalid value for --maxitems: %s\n", opt);\r
101 +               return 1;\r
102 +           }\r
103         } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
104             opt = argv[i] + sizeof ("--format=") - 1;\r
105             if (strcmp (opt, "text") == 0) {\r
106 @@ -473,6 +482,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
107      }\r
108  \r
109      notmuch_query_set_sort (query, sort);\r
110 +    notmuch_query_set_maxitems (query, maxitems);\r
111  \r
112      switch (output) {\r
113      default:\r
114 -- \r
115 1.7.5.4\r
116 \r