Re: [PATCH v3 0/8] emacs: JSON-based search cleanups
authorMark Walters <markwalters1009@gmail.com>
Sun, 15 Jul 2012 08:34:50 +0000 (09:34 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:20 +0000 (09:48 -0800)
22/27b92af146d90432790257313635ccb5aed950 [new file with mode: 0644]

diff --git a/22/27b92af146d90432790257313635ccb5aed950 b/22/27b92af146d90432790257313635ccb5aed950
new file mode 100644 (file)
index 0000000..092647f
--- /dev/null
@@ -0,0 +1,270 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 F0888431FBD\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Jul 2012 01:34:58 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 IU2HnO3dXohL for <notmuch@notmuchmail.org>;\r
+       Sun, 15 Jul 2012 01:34:58 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C4F61431FBC\r
+       for <notmuch@notmuchmail.org>; Sun, 15 Jul 2012 01:34:57 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1SqKI0-0005gI-Hv; Sun, 15 Jul 2012 09:34:52 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1SqKI0-0005B9-15; Sun, 15 Jul 2012 09:34:52 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 0/8] emacs: JSON-based search cleanups\r
+In-Reply-To: <1342306940-7499-1-git-send-email-amdragon@mit.edu>\r
+References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
+       <1342306940-7499-1-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.13.2+90~g84fa1ef (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sun, 15 Jul 2012 09:34:50 +0100\r
+Message-ID: <87fw8ttob9.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 1ec6910cedca53a5c076c0e4b06066f6 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Sun, 15 Jul 2012 08:34:59 -0000\r
+\r
+On Sun, 15 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> This version swaps out the notmuch-search-do-results macro for a\r
+> higher-order function, notmuch-search-foreach-result.  This requires\r
+> less squiting to understand and clearly distinguishes the arguments\r
+> passed in to the function from the arguments passed to the callback.\r
+> This version also updates the docstring for\r
+> notmuch-search-result-format to mention that multi-line result formats\r
+> work and how to enter them, and it adds a NEWS patch.\r
+\r
+Hi \r
+\r
+In essence this version looks good and, contrary to what I though\r
+before, I do prefer this function version to the macro. In addition it\r
+seems to work well in testing.\r
+\r
+However, there are some problems with multiline search results (see\r
+below) so I think we should either fix these or just downplay this new\r
+functionality by, for example, removing the comments on newlines from\r
+the defcustom and saying in NEWS that the feature is experimental/not\r
+complete or similar. (NEWS could say how to enter newlines in the\r
+defcustom)\r
+\r
+With this minor comment on the documentation my criticisms should not\r
+hold up this excellent series.\r
+\r
+Multiline oddities and todo\r
+\r
+There is still some strange scrolling when updating a result. One\r
+example that seems reproducible is if the search format has trailing\r
+newline and the cursor is at the start of that line it may jump to the\r
+far right of the previous line (possibly scrolling the screen\r
+horizontally) upon a tag change (eg +unread).\r
+\r
+If the format has a newline at the start of the author field it\r
+sometimes gets omitted from the output. (In addition to the known\r
+problem at the end of the author field that Austin mentions in the\r
+documentation for the defcustom).\r
+\r
+Examples of "incompleteness": these are rather more personal but it\r
+seems odd to me to highlight one line rather than one result in the\r
+buffer. Similarly I would expect <up> <down> to scroll up or down by\r
+one result rather than one line.\r
+\r
+I have a draft patch which fixes these two and mostly fixes the\r
+scrolling but it is bigger than I would like (and I haven't yet ironed\r
+out/checked all corner cases). I will split it up and send to the list\r
+so people can try it (but it is not intended as a submission\r
+currently).\r
+\r
+As it seems to be tricky to get fully right it might be preferable\r
+just to change the documentation as suggested above and leave\r
+multi-line to the adventurous.\r
+\r
+Best wishes \r
+\r
+Mark\r
+\r
+>\r
+> Diff from v2:\r
+>\r
+> diff --git a/NEWS b/NEWS\r
+> index a1a6e93..7b33f0d 100644\r
+> --- a/NEWS\r
+> +++ b/NEWS\r
+> @@ -17,6 +17,20 @@ Maildir tag synchronization\r
+>  Emacs Interface\r
+>  ---------------\r
+>  \r
+> +Search results now get re-colored when tags are updated\r
+> +\r
+> +The formatting of tags in search results can now be customized\r
+> +\r
+> +  Previously, attempting to change the format of tags in\r
+> +  `notmuch-search-result-format` would usually break tagging from\r
+> +  search-mode.  We no longer make assumptions about the format.\r
+> +\r
+> +Multi-line search result formats are now supported\r
+> +\r
+> +  It is now possible to embed newlines in\r
+> +  `notmuch-search-result-format` to make individual search results\r
+> +  span multiple lines.\r
+> +\r
+>  Search now uses the JSON format internally\r
+>  \r
+>    This should address problems with unusual characters in authors and\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index 7302fa7..ec760dc 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -69,7 +69,13 @@\r
+>      date, count, authors, subject, tags\r
+>  For example:\r
+>      (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
+> -                                         \(\"subject\" . \"%s\"\)\)\)"\r
+> +                                         \(\"subject\" . \"%s\"\)\)\)\r
+> +Line breaks are permitted in format strings.  Note that a line\r
+> +break at the end of an \"authors\" field will get elided if the\r
+> +authors list is long; place it instead at the beginning of the\r
+> +following field.  To enter a line break when setting this\r
+> +variable with setq, use \\n.  To enter a line break in customize,\r
+> +press \\[quoted-insert] C-j."\r
+>    :type '(alist :key-type (string) :value-type (string))\r
+>    :group 'notmuch-search)\r
+>  \r
+> @@ -433,32 +439,39 @@ returns nil"\r
+>      (next-single-property-change (or pos (point)) 'notmuch-search-result\r
+>                               nil (point-max))))\r
+>  \r
+> -(defmacro notmuch-search-do-results (beg end pos-sym &rest body)\r
+> -  "Invoke BODY for each result between BEG and END.\r
+> -\r
+> -POS-SYM will be bound to the point at the beginning of the\r
+> -current result."\r
+> -  (declare (indent 3))\r
+> -  (let ((end-sym (make-symbol "end"))\r
+> -    (first-sym (make-symbol "first")))\r
+> -    `(let ((,pos-sym (notmuch-search-result-beginning ,beg))\r
+> -       ;; End must be a marker in case body changes the text\r
+> -       (,end-sym (copy-marker ,end))\r
+> -       ;; Make sure we examine one result, even if (= beg end)\r
+> -       (,first-sym t))\r
+> -       ;; We have to be careful if the region extends beyond the\r
+> -       ;; results.  In this case, pos could be null or there could be\r
+> -       ;; no result at pos.\r
+> -       (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))\r
+> -     (when (notmuch-search-get-result ,pos-sym)\r
+> -       ,@body)\r
+> -     (setq ,pos-sym (notmuch-search-result-end ,pos-sym)\r
+> -           ,first-sym nil)))))\r
+> +(defun notmuch-search-foreach-result (beg end function)\r
+> +  "Invoke FUNCTION for each result between BEG and END.\r
+> +\r
+> +FUNCTION should take one argument.  It will be applied to the\r
+> +character position of the beginning of each result that overlaps\r
+> +the region between points BEG and END.  As a special case, if (=\r
+> +BEG END), FUNCTION will be applied to the result containing point\r
+> +BEG."\r
+> +\r
+> +  (lexical-let ((pos (notmuch-search-result-beginning beg))\r
+> +            ;; End must be a marker in case function changes the\r
+> +            ;; text.\r
+> +            (end (copy-marker end))\r
+> +            ;; Make sure we examine at least one result, even if\r
+> +            ;; (= beg end).\r
+> +            (first t))\r
+> +    ;; We have to be careful if the region extends beyond the results.\r
+> +    ;; In this case, pos could be null or there could be no result at\r
+> +    ;; pos.\r
+> +    (while (and pos (or (< pos end) first))\r
+> +      (when (notmuch-search-get-result pos)\r
+> +    (funcall function pos))\r
+> +      (setq pos (notmuch-search-result-end pos)\r
+> +        first nil))))\r
+> +;; Unindent the function argument of notmuch-search-foreach-result so\r
+> +;; the indentation of callers doesn't get out of hand.\r
+> +(put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
+>  \r
+>  (defun notmuch-search-properties-in-region (property beg end)\r
+>    (let (output)\r
+> -    (notmuch-search-do-results beg end pos\r
+> -      (push (plist-get (notmuch-search-get-result pos) property) output))\r
+> +    (notmuch-search-foreach-result beg end\r
+> +      (lambda (pos)\r
+> +    (push (plist-get (notmuch-search-get-result pos) property) output)))\r
+>      output))\r
+>  \r
+>  (defun notmuch-search-find-thread-id ()\r
+> @@ -542,18 +555,20 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
+>  \r
+>  (defun notmuch-search-get-tags-region (beg end)\r
+>    (let (output)\r
+> -    (notmuch-search-do-results beg end pos\r
+> -      (setq output (append output (notmuch-search-get-tags pos))))\r
+> +    (notmuch-search-foreach-result beg end\r
+> +      (lambda (pos)\r
+> +    (setq output (append output (notmuch-search-get-tags pos)))))\r
+>      output))\r
+>  \r
+>  (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
+>    "Change tags for threads in the given region."\r
+>    (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
+>      (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
+> -    (notmuch-search-do-results beg end pos\r
+> -      (notmuch-search-set-tags\r
+> -       (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
+> -       pos))))\r
+> +    (notmuch-search-foreach-result beg end\r
+> +      (lambda (pos)\r
+> +    (notmuch-search-set-tags\r
+> +     (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
+> +     pos)))))\r
+>  \r
+>  (defun notmuch-search-tag (&optional tag-changes)\r
+>    "Change tags for the currently selected thread or region.\r