Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 83AF0429E21 for ; Sun, 13 Nov 2011 08:50:10 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ik4EM4A199m2 for ; Sun, 13 Nov 2011 08:50:09 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 6EA74431FB6 for ; Sun, 13 Nov 2011 08:50:09 -0800 (PST) X-AuditID: 1209190f-b7f6e6d0000008df-58-4ebff53e6fa7 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id 70.BA.02271.E35FFBE4; Sun, 13 Nov 2011 11:50:06 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id pADGo4Id005198; Sun, 13 Nov 2011 11:50:04 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pADGnx4e018984 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 13 Nov 2011 11:50:01 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RPdI3-0001cm-RV; Sun, 13 Nov 2011 11:52:19 -0500 From: Austin Clements To: Jani Nikula , notmuch@notmuchmail.org Subject: Re: [PATCH v4 2/6] cli: add options --first and --maxitems to notmuch search In-Reply-To: <45e0f0f47250b20b4c3372910fea4d2fd5144e20.1320615322.git.jani@nikula.org> References: <45e0f0f47250b20b4c3372910fea4d2fd5144e20.1320615322.git.jani@nikula.org> User-Agent: Notmuch/0.9+29~g81d35f0 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) Date: Sun, 13 Nov 2011 11:52:19 -0500 Message-ID: <87ehxcufr0.fsf@awakening.csail.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnleLIzCtJLcpLzFFi42IRYrdT0bX7ut/PYPkOE4vevYvZLG60djNa /G+utmia7myxZ5+XxfWbM5kd2DzunubymNT1jMnj1v3X7B7PVt1i9pi09iSLx5ZD75kD2KK4 bFJSczLLUov07RK4Mqa9WsJYcM2u4uSZ5WwNjH36XYycHBICJhKNT9pZIWwxiQv31rN1MXJx CAnsY5T4/OQ5M4SzgVHiQmMzE4RzkknixNM/UM4SRolrG36ygfSzCWhIbNu/nBHEFhGwkjj3 8DVLFyMHB7NAhUTT5ViQsLBAqMSbLZvYQMKcAmESs2+EgoSFBGokes7cZQaxRQViJY5eWcYI UsIioCrx4qsrSJgX6NCWL3dYIGxBiZMzn4DZzAJaEjf+vWSawCg4C0lqFpLUAkamVYyyKblV urmJmTnFqcm6xcmJeXmpRbomermZJXqpKaWbGEHhzinJv4Px20GlQ4wCHIxKPLwO0vv9hFgT y4orcw8xSnIwKYnyXvgMFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCW7kCKMebklhZlVqUD5OS 5mBREudt3OHgJySQnliSmp2aWpBaBJOV4eBQkuDt/ALUKFiUmp5akZaZU4KQZuLgBBnOAzS8 HaSGt7ggMbc4Mx0if4pRUUqc9zJIQgAkkVGaB9cLS0evGMWBXhHm7QCp4gGmMrjuV0CDmYAG syjsBRlckoiQkmpgXBoQxSAutO5arBYHyxGrk+tmc2WxtV9+8+kR16YQu39Pc9gKfi88kyHo fCrl76zUBov8i2ujXP1VsssYPBf5tavrFppWiPp27163hfdL/nOlaRFKivH7/htZVYfO4bqz zJPV498a+bnKJ0/XGMpzh58+9z2539r3V0GJad2M5C3SBy+J3OxRYinOSDTUYi4qTgQAv3Lk LSIDAAA= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Nov 2011 16:50:10 -0000 Code LGTM. Some documentation nits below. On Sun, 6 Nov 2011 23:47:11 +0200, Jani Nikula wrote: > Add options --first=[-]N and --maxitems=M to notmuch search to determine > the first result and maximum number of results to display. > > Option --maxitems=M limits the maximum number of results to display to M. > > Option --first=[-]N skips the first N results; with the leading '-' skip > until the Nth result from the end (showing a total of N results if within > bounds of the total number of results and not limited with --maxitems). > > Note that --first with a negative N for thread or summary output requires > counting the number of matching threads in advance. > > Signed-off-by: Jani Nikula > --- > NEWS | 5 ++++ > notmuch-search.c | 70 ++++++++++++++++++++++++++++++++++++++++++++--------- > notmuch.1 | 21 ++++++++++++++- > 3 files changed, 82 insertions(+), 14 deletions(-) > > diff --git a/NEWS b/NEWS > index b44b11e..bfdba7b 100644 > --- a/NEWS > +++ b/NEWS > @@ -23,6 +23,11 @@ Add search terms to "notmuch dump" > search/show/tag. The output file argument of dump is deprecated in > favour of using stdout. > > +Add "notmuch search" --first and --maxitems options > + > + The search command now takes options --first=[-]N and --maxitems=N to limit > + the number of results shown. > + > Notmuch 0.9 (2011-10-01) > ======================== > > diff --git a/notmuch-search.c b/notmuch-search.c > index 6f04d9a..c62a594 100644 > --- a/notmuch-search.c > +++ b/notmuch-search.c > @@ -194,13 +194,22 @@ static int > do_search_threads (const search_format_t *format, > notmuch_query_t *query, > notmuch_sort_t sort, > - output_t output) > + output_t output, > + int first, > + int maxitems) > { > notmuch_thread_t *thread; > notmuch_threads_t *threads; > notmuch_tags_t *tags; > time_t date; > int first_thread = 1; > + int i; > + > + if (first < 0) { > + first += notmuch_query_count_threads (query); > + if (first < 0) > + first = 0; > + } > > threads = notmuch_query_search_threads (query); > if (threads == NULL) > @@ -208,17 +217,23 @@ do_search_threads (const search_format_t *format, > > fputs (format->results_start, stdout); > > - for (; > - notmuch_threads_valid (threads); > - notmuch_threads_move_to_next (threads)) > + for (i = 0; > + notmuch_threads_valid (threads) && > + (maxitems < 0 || i < first + maxitems); > + notmuch_threads_move_to_next (threads), i++) > { > int first_tag = 1; > > + thread = notmuch_threads_get (threads); > + > + if (i < first) { > + notmuch_thread_destroy (thread); > + continue; > + } > + > if (! first_thread) > fputs (format->item_sep, stdout); > > - thread = notmuch_threads_get (threads); > - > if (output == OUTPUT_THREADS) { > format->item_id (thread, "thread:", > notmuch_thread_get_thread_id (thread)); > @@ -271,12 +286,21 @@ do_search_threads (const search_format_t *format, > static int > do_search_messages (const search_format_t *format, > notmuch_query_t *query, > - output_t output) > + output_t output, > + int first, > + int maxitems) > { > notmuch_message_t *message; > notmuch_messages_t *messages; > notmuch_filenames_t *filenames; > int first_message = 1; > + int i; > + > + if (first < 0) { > + first += notmuch_query_count_messages (query); > + if (first < 0) > + first = 0; > + } > > messages = notmuch_query_search_messages (query); > if (messages == NULL) > @@ -284,10 +308,14 @@ do_search_messages (const search_format_t *format, > > fputs (format->results_start, stdout); > > - for (; > - notmuch_messages_valid (messages); > - notmuch_messages_move_to_next (messages)) > + for (i = 0; > + notmuch_messages_valid (messages) && > + (maxitems < 0 || i < first + maxitems); > + notmuch_messages_move_to_next (messages), i++) > { > + if (i < first) > + continue; > + > message = notmuch_messages_get (messages); > > if (output == OUTPUT_FILES) { > @@ -394,6 +422,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) > const search_format_t *format = &format_text; > int i, ret; > output_t output = OUTPUT_SUMMARY; > + int maxitems = -1; /* unlimited */ > + int first = 0; > > argc--; argv++; /* skip subcommand argument */ > > @@ -412,6 +442,22 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) > fprintf (stderr, "Invalid value for --sort: %s\n", opt); > return 1; > } > + } else if (STRNCMP_LITERAL (argv[i], "--first=") == 0) { > + char *p; > + opt = argv[i] + sizeof ("--first=") - 1; > + first = strtol (opt, &p, 10); > + if (*opt == '\0' || p == opt || *p != '\0') { > + fprintf (stderr, "Invalid value for --first: %s\n", opt); > + return 1; > + } > + } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) { > + char *p; > + opt = argv[i] + sizeof ("--maxitems=") - 1; > + maxitems = strtoul (opt, &p, 10); > + if (*opt == '\0' || p == opt || *p != '\0') { > + fprintf (stderr, "Invalid value for --maxitems: %s\n", opt); > + return 1; > + } > } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) { > opt = argv[i] + sizeof ("--format=") - 1; > if (strcmp (opt, "text") == 0) { > @@ -478,11 +524,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) > default: > case OUTPUT_SUMMARY: > case OUTPUT_THREADS: > - ret = do_search_threads (format, query, sort, output); > + ret = do_search_threads (format, query, sort, output, first, maxitems); > break; > case OUTPUT_MESSAGES: > case OUTPUT_FILES: > - ret = do_search_messages (format, query, output); > + ret = do_search_messages (format, query, output, first, maxitems); > break; > case OUTPUT_TAGS: > ret = do_search_tags (notmuch, format, query); > diff --git a/notmuch.1 b/notmuch.1 > index bba479e..c97334c 100644 > --- a/notmuch.1 > +++ b/notmuch.1 > @@ -214,11 +214,28 @@ when sorting by > .B newest\-first > the threads will be sorted by the newest message in each thread. > > -.RE > -.RS 4 > By default, results will be displayed in reverse chronological order, > (that is, the newest results will be displayed first). > +.RE > + > +.RS 4 > +.TP 4 > +.BR \-\-first=[\-]N > + > +This option can be used to skip the display of first N results. With the To be consistent with the other documentation style, this should be "Skip the display of the first N results." (or, better, "Skip displaying the first N results.") > +leading '\-' skip until the Nth result from the end, showing a total of N > +results if not otherwise bounded by total number of matching results or > +\-\-maxitems. ".. if not otherwise bounded by total number of matching results .." I see what you're saying here, but I read this over several times before it clicked that you were talking about being bounded by the *beginning* of the search results, not the *end* of the search results. I don't think it's necessary to talk about the bounding here at all. Obviously it can't give you more search results than there are, and maxitems is discussed separately. Perhaps just "With the leading '\-', start at the Nth result from the end."? > +.RE > + > +.RS 4 > +.TP 4 > +.BR \-\-maxitems=N > > +This option can be used to limit the number of results to display to N. Likewise, "Limit the number results to display to N." (or, better, "Limit the number of displayed results to N.") > +.RE > + > +.RS 4 > See the > .B "SEARCH SYNTAX" > section below for details of the supported syntax for . > -- > 1.7.5.4 >