Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6D3396DE0FB0 for ; Mon, 14 Dec 2015 09:23:16 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.291 X-Spam-Level: X-Spam-Status: No, score=-0.291 tagged_above=-999 required=5 tests=[AWL=0.279, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fqzsqsyfQvnX for ; Mon, 14 Dec 2015 09:23:14 -0800 (PST) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by arlo.cworth.org (Postfix) with ESMTPS id 714556DE0C81 for ; Mon, 14 Dec 2015 09:23:11 -0800 (PST) Received: by mail-wm0-f48.google.com with SMTP id n186so128391207wmn.1 for ; Mon, 14 Dec 2015 09:23:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PCa8grG5MiugKV644tQbvyLnhUZq1vMy9cG8O9yT69M=; b=Ce2+mTcY6Mr6Y5VU5CtwZaqOGzgk1K0ST0GoQIhs6yhqpzysNfu+sLa9T7pkjAINH9 ZD2BNWPOKxlRL1OfY26urh5Szjlp7Rg7emKtbF4WXHtWolaFXaUQxc+4GAh5LcMtReBT rBJ7w2EcxKWcr6meWGd7mbAXvl9//0hy79+XYSZA1YcEi9Tru5McefuC+RtvC/AKF7hP 4Oxnue5Fyqg71A/9R9zjHx6P1bIZLN6jr3DTVIl+Ej+B/LJJof6mr4Yo2r7ojRlu3D6v YyGnAcz4gBrSlDMyQYZYDJ/5jt1vFdbw5PfT+z6VBQwveANogecQmBhAjgkcdBKOLMqx NVuQ== X-Received: by 10.28.65.69 with SMTP id o66mr23978797wma.18.1450113787777; Mon, 14 Dec 2015 09:23:07 -0800 (PST) Received: from localhost (92.40.77.76.threembb.co.uk. [92.40.77.76]) by smtp.gmail.com with ESMTPSA id h5sm30668485wjz.21.2015.12.14.09.23.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Dec 2015 09:23:06 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v2 (rebased) 2/3] emacs: Improved display of matching/non-matching authors. Date: Mon, 14 Dec 2015 17:22:45 +0000 Message-Id: <1450113766-20518-3-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1450113766-20518-1-git-send-email-markwalters1009@gmail.com> References: <1450113766-20518-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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: Mon, 14 Dec 2015 17:23:16 -0000 From: David Edmondson Rather than splitting the :authors attribute, which is error prone, use the separate :authors_matched and :authors_non_matched attributes. This improves the display of authors should one of them include a pipe symbol (|) in their 'from' address. --- emacs/notmuch.el | 64 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 463b926..1f4f6c3 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -674,22 +674,24 @@ foreground and blue background." ;; Reverse the list so earlier entries take precedence (reverse notmuch-search-line-faces))) -(defun notmuch-search-author-propertize (authors) +(defun notmuch-search-author-propertize (authors matching-length) "Split `authors' into matching and non-matching authors and propertize appropriately. If no boundary between authors and non-authors is found, assume that all of the authors match." - (if (string-match "\\(.*\\)|\\(.*\\)" authors) - (concat (propertize (concat (match-string 1 authors) ",") - 'face 'notmuch-search-matching-authors) - (propertize (match-string 2 authors) - 'face 'notmuch-search-non-matching-authors)) - (propertize authors 'face 'notmuch-search-matching-authors))) - -(defun notmuch-search-insert-authors (format-string authors) + (let ((match-part (substring authors 0 matching-length)) + (non-match-part (substring authors matching-length))) + + (concat (propertize match-part 'face 'notmuch-search-matching-authors) + (propertize non-match-part 'face 'notmuch-search-non-matching-authors)))) + +(defun notmuch-search-insert-authors (format-string matching-authors non-matching-authors) ;; Save the match data to avoid interfering with ;; `notmuch-search-process-filter'. (save-match-data - (let* ((formatted-authors (format format-string authors)) + (let* ((authors (if (string= "" non-matching-authors) + matching-authors + (concat matching-authors ", " non-matching-authors))) + (formatted-authors (format format-string authors)) (formatted-sample (format format-string "")) (visible-string formatted-authors) (invisible-string "") @@ -705,9 +707,9 @@ non-authors is found, assume that all of the authors match." (setq visible-string (substring formatted-authors 0 visible-length) invisible-string (substring formatted-authors visible-length)) ;; If possible, truncate the visible string at a natural - ;; break (comma or pipe), as incremental search doesn't - ;; match across the visible/invisible border. - (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string) + ;; break (comma), as incremental search doesn't match + ;; across the visible/invisible border. + (when (string-match "\\(.*\\)\\(, \\)\\([^,]*\\)" visible-string) ;; Second clause is destructive on `visible-string', so ;; order is important. (setq invisible-string (concat (match-string 3 visible-string) @@ -723,20 +725,23 @@ non-authors is found, assume that all of the authors match." ? )))) ;; Use different faces to show matching and non-matching authors. - (if (string-match "\\(.*\\)|\\(.*\\)" visible-string) - ;; The visible string contains both matching and - ;; non-matching authors. - (setq visible-string (notmuch-search-author-propertize visible-string) - ;; The invisible string must contain only non-matching - ;; authors, as the visible-string contains both. - invisible-string (propertize invisible-string - 'face 'notmuch-search-non-matching-authors)) - ;; The visible string contains only matching authors. - (setq visible-string (propertize visible-string - 'face 'notmuch-search-matching-authors) - ;; The invisible string may contain both matching and - ;; non-matching authors. - invisible-string (notmuch-search-author-propertize invisible-string))) + (let ((visible-length (length visible-string)) + (matching-length (length matching-authors))) + + (if (> visible-length matching-length) + ;; The visible string contains both matching and + ;; non-matching authors. + (setq visible-string (notmuch-search-author-propertize visible-string matching-length) + ;; The invisible string must contain only non-matching + ;; authors, as the visible-string contains both. + invisible-string (propertize invisible-string + 'face 'notmuch-search-non-matching-authors)) + ;; The visible string contains only matching authors. + (setq visible-string (propertize visible-string + 'face 'notmuch-search-matching-authors) + ;; The invisible string may contain both matching and + ;; non-matching authors. + invisible-string (notmuch-search-author-propertize invisible-string (- visible-length matching-length))))) ;; If there is any invisible text, add it as a tooltip to the ;; visible text. @@ -770,8 +775,9 @@ non-authors is found, assume that all of the authors match." 'face 'notmuch-search-subject))) ((string-equal field "authors") - (notmuch-search-insert-authors - format-string (notmuch-sanitize (plist-get result :authors)))) + (notmuch-search-insert-authors format-string + (notmuch-sanitize (mapconcat 'identity (plist-get result :authors_matched) ", ")) + (notmuch-sanitize (mapconcat 'identity (plist-get result :authors_non_matched) ", ")))) ((string-equal field "tags") (let ((tags (plist-get result :tags)) -- 2.1.4