--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1D632421191\r
+ for <notmuch@notmuchmail.org>; Mon, 3 Jun 2013 02:42:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id vk6-ZVVLGxw3 for <notmuch@notmuchmail.org>;\r
+ Mon, 3 Jun 2013 02:42:13 -0700 (PDT)\r
+Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com\r
+ [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ B04AB421180 for <notmuch@notmuchmail.org>; Mon, 3 Jun 2013 02:42:13 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f41.google.com with SMTP id k13so2493258wgh.2\r
+ for <notmuch@notmuchmail.org>; Mon, 03 Jun 2013 02:42:11 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer;\r
+ bh=fFPkO/0noVmfeJAYHc4MG/29zRFgaNZHr45CbY0/beo=;\r
+ b=uoxGFYhzOCxCVqDZvqS9K3fH0KboIhbJuEHGqsQQm6kQkEMtlnTtXpzScRkTVDTgMT\r
+ NKgGaFu8lWcXIWSmS+ml+qPeKuoEK9GivzD6OUipttW0xd3Nhc64F5gYY2JdIl79LccY\r
+ X/LdkTP3tE6a67E7u/i9Bh5xNyRr/XM5s7EkFeANmLq+2HTxUGxqE6KN1xLW0iNKbqwQ\r
+ PeSG1NSTXX4RjuBF7Ox56ZoOEhFMO5LjrLDm909RKES1ECM1ug538XoqBOd0FyC5Q8RN\r
+ cL9vnm/53lBK1p8FQ05YR81d0m6p8uPZvMVAxCK4sIzoLPHStJhCbQtmndHBY9sDp/Rs\r
+ sF+w==\r
+X-Received: by 10.194.249.231 with SMTP id yx7mr7432993wjc.13.1370252531175;\r
+ Mon, 03 Jun 2013 02:42:11 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id\r
+ fu14sm22205396wic.0.2013.06.03.02.42.09 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Mon, 03 Jun 2013 02:42:10 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+ jani@nikula.org\r
+Subject: [RFC PATCH] emacs: search: allow command line args as part of query\r
+Date: Mon, 3 Jun 2013 10:42:06 +0100\r
+Message-Id: <1370252526-18003-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 03 Jun 2013 09:42:24 -0000\r
+\r
+This allows command line arguments for notmuch-search to be part of\r
+the query-string. The string must be of the form\r
+[:blank:]*--cli-arguments -- query. I hope this doesn't clash with\r
+xapian: I believe that queries shouldn't start with a "-".\r
+\r
+Correctly parsed example queries are\r
+--sort=oldest-first -- tag:inbox\r
+--exclude=false -- from:fred\r
+\r
+Some options (currently only sort-order) we parse in emacs, the rest\r
+we just pass to the cli. In light testing it seems to work.\r
+\r
+A full custom parser would be nicer but at least here we are only parsing\r
+the non-query part of a string which is relatively simple: indeed we\r
+already do that in the c code.\r
+\r
+We could just implement the option for sort-order, but I thought for\r
+interface consistency making all the options (sort-order exclude limit\r
+and offset) work was worth the small extra hassle.\r
+---\r
+\r
+This is an attempt to achieve the same as\r
+id:1349209083-7170-1-git-send-email-jani@nikula.org : that is allow a\r
+saved search to specify the query sort order. However, this is a\r
+rather more complete solution (note as this might be viewed a hack\r
+minimal may be *better* than complete): it works for any search (saved\r
+or from "s") and lets other options (exclude etc) work. What do people\r
+think?\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+ emacs/notmuch.el | 31 ++++++++++++++++++++++++++-----\r
+ 1 files changed, 26 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 7994d74..26ba7e7 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -255,6 +255,7 @@ For a mouse binding, return nil."\r
+ (notmuch-common-do-stash (notmuch-search-find-thread-id)))\r
+ \r
+ (defvar notmuch-search-query-string)\r
++(defvar notmuch-search-full-query)\r
+ (defvar notmuch-search-target-thread)\r
+ (defvar notmuch-search-target-line)\r
+ (defvar notmuch-search-continuation)\r
+@@ -409,6 +410,7 @@ Complete list of currently available key bindings:\r
+ (interactive)\r
+ (kill-all-local-variables)\r
+ (make-local-variable 'notmuch-search-query-string)\r
++ (make-local-variable 'notmuch-search-full-query)\r
+ (make-local-variable 'notmuch-search-oldest-first)\r
+ (make-local-variable 'notmuch-search-target-thread)\r
+ (make-local-variable 'notmuch-search-target-line)\r
+@@ -896,6 +898,26 @@ PROMPT is the string to prompt with."\r
+ (read-from-minibuffer prompt nil keymap nil\r
+ 'notmuch-search-history nil nil)))))\r
+ \r
++(defun notmuch-search-parse-query (query oldest-first)\r
++ (setq notmuch-search-oldest-first oldest-first)\r
++ (if (string-match "^[:blank:]*--.*? -- " query)\r
++ (let ((actual-query (substring query (match-end 0)))\r
++ (args (split-string (match-string 0 query) " " t)))\r
++ (setq notmuch-search-query-string actual-query)\r
++ (dolist (arg args nil)\r
++ (when (equal arg "--sort=oldest-first")\r
++ (setq notmuch-search-oldest-first t)\r
++ (message "oldest first found"))\r
++ (when (equal arg "--sort=newest-first")\r
++ (setq notmuch-search-oldest-first nil)\r
++ (message "newest first found")))\r
++ (setq args (delete "--sort=oldest-first" args))\r
++ (setq args (delete "--sort=newest-first" args))\r
++ (setq notmuch-search-full-query (append args (list actual-query))))\r
++ ;; no special arguments\r
++ (setq notmuch-search-full-query (list query))\r
++ (setq notmuch-search-query-string query)))\r
++\r
+ ;;;###autoload\r
+ (defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
+ "Run \"notmuch search\" with the given `query' and display results.\r
+@@ -915,8 +937,7 @@ Other optional parameters are used as follows:\r
+ (notmuch-search-mode)\r
+ ;; Don't track undo information for this buffer\r
+ (set 'buffer-undo-list t)\r
+- (set 'notmuch-search-query-string query)\r
+- (set 'notmuch-search-oldest-first oldest-first)\r
++ (notmuch-search-parse-query query oldest-first)\r
+ (set 'notmuch-search-target-thread target-thread)\r
+ (set 'notmuch-search-target-line target-line)\r
+ (set 'notmuch-search-continuation continuation)\r
+@@ -928,13 +949,13 @@ Other optional parameters are used as follows:\r
+ (erase-buffer)\r
+ (goto-char (point-min))\r
+ (save-excursion\r
+- (let ((proc (notmuch-start-notmuch\r
++ (let ((proc (apply #'notmuch-start-notmuch\r
+ "notmuch-search" buffer #'notmuch-search-process-sentinel\r
+ "search" "--format=sexp" "--format-version=1"\r
+- (if oldest-first\r
++ (if notmuch-search-oldest-first\r
+ "--sort=oldest-first"\r
+ "--sort=newest-first")\r
+- query))\r
++ notmuch-search-full-query))\r
+ ;; Use a scratch buffer to accumulate partial output.\r
+ ;; This buffer will be killed by the sentinel, which\r
+ ;; should be called no matter how the process dies.\r
+-- \r
+1.7.9.1\r
+\r