[PATCH v2 2/3] emacs: Improved display of matching/non-matching authors.
authorDavid Edmondson <dme@dme.org>
Fri, 24 Oct 2014 17:44:02 +0000 (18:44 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:05:39 +0000 (10:05 -0800)
9f/8dc4e00775126478ec5bf5b94dccf20a6449d3 [new file with mode: 0644]

diff --git a/9f/8dc4e00775126478ec5bf5b94dccf20a6449d3 b/9f/8dc4e00775126478ec5bf5b94dccf20a6449d3
new file mode 100644 (file)
index 0000000..ccf6328
--- /dev/null
@@ -0,0 +1,186 @@
+Return-Path: <dme@dme.org>\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 B6122429E29\r
+       for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:19 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]\r
+       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 7pKTalzzxjNx for <notmuch@notmuchmail.org>;\r
+       Fri, 24 Oct 2014 10:44:14 -0700 (PDT)\r
+Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com\r
+       [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 2F8CC431FD4\r
+       for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:10 -0700 (PDT)\r
+Received: by mail-wi0-f171.google.com with SMTP id em10so1835055wid.10\r
+       for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 10:44:08 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:user-agent:from:to:subject:date:message-id\r
+       :in-reply-to:references;\r
+       bh=1QzqHNoTT+e5VIRb9bqb9Fbp8QK0Ume+uAAxTjqO3KY=;\r
+       b=iPE3gL4lxCGtaIvC0Nn84bOCyRjqsmb6xvTkvLubOlX2BvY8OrMYTE4Q6Tz8xaCau+\r
+       2dJL60F4VeFoeSbXE8zlPdO3NYhpX4yOjnQUteVbIoP01Aiug/hcaQO/VHAvf9InZqcg\r
+       HIzEKM10UYjYdBovzlbp8CTPHmEvATy8JA+zbS9Ly56FZDFKgLiF1SyVbNAr2s87vDmb\r
+       ULzh3nDfIGH9RC5xkGhslBhMW9E4x6Ns8NFNWIP+McAt3k07PG4M4g3IIQKxsKvUPcPd\r
+       9d9ZnPPzDPT4/qsUDlk29+ehpm56fY8X6BAE30Q+OAmVD1PkdJpRJjHw5xQmreYYVyfX\r
+       CKew==\r
+X-Gm-Message-State:\r
+ ALoCoQlYiVRaQVc9Ich2jDoB3aKeNx9OGfS00KoI95pV/I1hnZGG5+bdDY4W+urE3ZiCcIt17qe7\r
+X-Received: by 10.194.91.176 with SMTP id cf16mr6320061wjb.60.1414172648571;\r
+       Fri, 24 Oct 2014 10:44:08 -0700 (PDT)\r
+Received: from disaster-area.hh.sledj.net\r
+       ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
+       by mx.google.com with ESMTPSA id u8sm2718196wiz.14.2014.10.24.10.44.07\r
+       for <notmuch@notmuchmail.org>\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Fri, 24 Oct 2014 10:44:07 -0700 (PDT)\r
+Received: from localhost (30000@localhost [local]);\r
+       by localhost (OpenSMTPD) with ESMTPA id f60902d2;\r
+       for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 17:44:03 +0000 (UTC)\r
+User-Agent: OpenSMTPD enqueuer (Demoostik)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/3] emacs: Improved display of matching/non-matching\r
+       authors.\r
+Date: Fri, 24 Oct 2014 18:44:02 +0100\r
+Message-Id: <1414172643-28270-3-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1414172643-28270-1-git-send-email-dme@dme.org>\r
+References: <1414172643-28270-1-git-send-email-dme@dme.org>\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: Fri, 24 Oct 2014 17:44:20 -0000\r
+\r
+Rather than splitting the :authors attribute, which is error prone,\r
+use the separate :authors_matched and :authors_non_matched attributes.\r
+\r
+This improves the display of authors should one of them include a pipe\r
+symbol (|) in their 'from' address.\r
+---\r
+ emacs/notmuch.el | 64 +++++++++++++++++++++++++++++++-------------------------\r
+ 1 file changed, 35 insertions(+), 29 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index b44a907..688b37c 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -672,22 +672,24 @@ foreground and blue background."\r
+       ;; Reverse the list so earlier entries take precedence\r
+       (reverse notmuch-search-line-faces)))\r
\r
+-(defun notmuch-search-author-propertize (authors)\r
++(defun notmuch-search-author-propertize (authors matching-length)\r
+   "Split `authors' into matching and non-matching authors and\r
+ propertize appropriately. If no boundary between authors and\r
+ non-authors is found, assume that all of the authors match."\r
+-  (if (string-match "\\(.*\\)|\\(.*\\)" authors)\r
+-      (concat (propertize (concat (match-string 1 authors) ",")\r
+-                        'face 'notmuch-search-matching-authors)\r
+-            (propertize (match-string 2 authors)\r
+-                        'face 'notmuch-search-non-matching-authors))\r
+-    (propertize authors 'face 'notmuch-search-matching-authors)))\r
+-\r
+-(defun notmuch-search-insert-authors (format-string authors)\r
++  (let ((match-part (substring authors 0 matching-length))\r
++      (non-match-part (substring authors matching-length)))\r
++\r
++      (concat (propertize match-part 'face 'notmuch-search-matching-authors)\r
++            (propertize non-match-part 'face 'notmuch-search-non-matching-authors))))\r
++\r
++(defun notmuch-search-insert-authors (format-string matching-authors non-matching-authors)\r
+   ;; Save the match data to avoid interfering with\r
+   ;; `notmuch-search-process-filter'.\r
+   (save-match-data\r
+-    (let* ((formatted-authors (format format-string authors))\r
++    (let* ((authors (if (string= "" non-matching-authors)\r
++                      matching-authors\r
++                    (concat matching-authors ", " non-matching-authors)))\r
++         (formatted-authors (format format-string authors))\r
+          (formatted-sample (format format-string ""))\r
+          (visible-string formatted-authors)\r
+          (invisible-string "")\r
+@@ -703,9 +705,9 @@ non-authors is found, assume that all of the authors match."\r
+           (setq visible-string (substring formatted-authors 0 visible-length)\r
+                 invisible-string (substring formatted-authors visible-length))\r
+           ;; If possible, truncate the visible string at a natural\r
+-          ;; break (comma or pipe), as incremental search doesn't\r
+-          ;; match across the visible/invisible border.\r
+-          (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string)\r
++          ;; break (comma), as incremental search doesn't match\r
++          ;; across the visible/invisible border.\r
++          (when (string-match "\\(.*\\)\\(, \\)\\([^,]*\\)" visible-string)\r
+             ;; Second clause is destructive on `visible-string', so\r
+             ;; order is important.\r
+             (setq invisible-string (concat (match-string 3 visible-string)\r
+@@ -721,20 +723,23 @@ non-authors is found, assume that all of the authors match."\r
+                                      ? ))))\r
\r
+       ;; Use different faces to show matching and non-matching authors.\r
+-      (if (string-match "\\(.*\\)|\\(.*\\)" visible-string)\r
+-        ;; The visible string contains both matching and\r
+-        ;; non-matching authors.\r
+-        (setq visible-string (notmuch-search-author-propertize visible-string)\r
+-              ;; The invisible string must contain only non-matching\r
+-              ;; authors, as the visible-string contains both.\r
+-              invisible-string (propertize invisible-string\r
+-                                           'face 'notmuch-search-non-matching-authors))\r
+-      ;; The visible string contains only matching authors.\r
+-      (setq visible-string (propertize visible-string\r
+-                                       'face 'notmuch-search-matching-authors)\r
+-            ;; The invisible string may contain both matching and\r
+-            ;; non-matching authors.\r
+-            invisible-string (notmuch-search-author-propertize invisible-string)))\r
++      (let ((visible-length (length visible-string))\r
++          (matching-length (length matching-authors)))\r
++\r
++      (if (> visible-length matching-length)\r
++          ;; The visible string contains both matching and\r
++          ;; non-matching authors.\r
++          (setq visible-string (notmuch-search-author-propertize visible-string matching-length)\r
++                ;; The invisible string must contain only non-matching\r
++                ;; authors, as the visible-string contains both.\r
++                invisible-string (propertize invisible-string\r
++                                             'face 'notmuch-search-non-matching-authors))\r
++        ;; The visible string contains only matching authors.\r
++        (setq visible-string (propertize visible-string\r
++                                         'face 'notmuch-search-matching-authors)\r
++              ;; The invisible string may contain both matching and\r
++              ;; non-matching authors.\r
++              invisible-string (notmuch-search-author-propertize invisible-string (- visible-length matching-length)))))\r
\r
+       ;; If there is any invisible text, add it as a tooltip to the\r
+       ;; visible text.\r
+@@ -768,8 +773,9 @@ non-authors is found, assume that all of the authors match."\r
+                       'face 'notmuch-search-subject)))\r
\r
+    ((string-equal field "authors")\r
+-    (notmuch-search-insert-authors\r
+-     format-string (notmuch-sanitize (plist-get result :authors))))\r
++    (notmuch-search-insert-authors format-string\r
++                                 (notmuch-sanitize (mapconcat 'identity (plist-get result :authors_matched) ", "))\r
++                                 (notmuch-sanitize (mapconcat 'identity (plist-get result :authors_non_matched) ", "))))\r
\r
+    ((string-equal field "tags")\r
+     (let ((tags (plist-get result :tags))\r
+-- \r
+2.1.1\r
+\r