From bd15befe53a1d48d8292444c49de4fc942c88c4d Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Mon, 19 Jan 2015 09:18:17 +0000 Subject: [PATCH] Re: [PATCH v2 2/3] emacs: Improved display of matching/non-matching authors. --- 29/067262eb0ca07c54ec36d5cd82d95cab969a2b | 214 ++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 29/067262eb0ca07c54ec36d5cd82d95cab969a2b diff --git a/29/067262eb0ca07c54ec36d5cd82d95cab969a2b b/29/067262eb0ca07c54ec36d5cd82d95cab969a2b new file mode 100644 index 000000000..e66125b5d --- /dev/null +++ b/29/067262eb0ca07c54ec36d5cd82d95cab969a2b @@ -0,0 +1,214 @@ +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 B3D53431FB6 + for ; Mon, 19 Jan 2015 01:18:24 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 1.739 +X-Spam-Level: * +X-Spam-Status: No, score=1.739 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7, + UNPARSEABLE_RELAY=0.001] 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 HEWAdpCx3JAm for ; + Mon, 19 Jan 2015 01:18:20 -0800 (PST) +Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com + [74.125.82.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 8D919431FAF for ; Mon, 19 Jan 2015 01:18:20 -0800 + (PST) +Received: by mail-wg0-f46.google.com with SMTP id x13so30543023wgg.5 + for ; Mon, 19 Jan 2015 01:18:19 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:to:subject:in-reply-to:references:user-agent + :from:date:message-id:mime-version:content-type; + bh=HKb+HJljNoXJ1QUmT5l46+3GC5UqXzw/Ix06XYznn/s=; + b=Py3AuPHcYPYDB5JTeGskQm1DnLeN7u9LLCRj8ff8aOHhKjJI/c2PkX6+BVIVmOSVQA + /iWEF5treYSXBY+x2lxM+9x4tS3hobsILTS+YOnIxfLKy74j8Ta5Y401c+IVMO3Zf/kS + mfGXhhgxXSOk2eN9c8y+EuOhTSfn3fsvEWmLzy698hnBMiO2Fnlikrc5wwojjtNwVhI6 + KW8eRDc8Hs3PLIpFkq81gOj1/eHorRsfJji4Q46zZjWFQq7MH3WkzjZchBmZ5lsuKS2A + ZYarR0GSBeImG+i9ylMlOMVWofG5+yvMqnMQxpuGxER6MeXaY/310OlBlk6+Ysz1ciSD + PiCw== +X-Gm-Message-State: + ALoCoQns778PiErCnuJ1/XBtyuy19rQebE8VV3uNCOQ2JPiVC+deoaZoFhzR/bB9askp4gkUH7G/ +X-Received: by 10.180.228.72 with SMTP id sg8mr33561156wic.48.1421659099365; + Mon, 19 Jan 2015 01:18:19 -0800 (PST) +Received: from disaster-area.hh.sledj.net + ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) + by mx.google.com with ESMTPSA id fp2sm13419444wib.8.2015.01.19.01.18.18 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Mon, 19 Jan 2015 01:18:18 -0800 (PST) +Received: from localhost (30000@localhost [local]); + by localhost (OpenSMTPD) with ESMTPA id d2b51c17; + Mon, 19 Jan 2015 09:18:17 +0000 (UTC) +To: Mark Walters , notmuch@notmuchmail.org +Subject: Re: [PATCH v2 2/3] emacs: Improved display of + matching/non-matching authors. +In-Reply-To: <87oapwj6xg.fsf@qmul.ac.uk> +References: <1414172643-28270-1-git-send-email-dme@dme.org> + <1414172643-28270-3-git-send-email-dme@dme.org> + <87oapwj6xg.fsf@qmul.ac.uk> +User-Agent: none +From: David Edmondson +Date: Mon, 19 Jan 2015 09:18:17 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain +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: Mon, 19 Jan 2015 09:18:24 -0000 + +On Sun, Jan 18 2015, Mark Walters wrote: +> On Fri, 24 Oct 2014, David Edmondson wrote: +>> 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. +> +> Hi +> +> I haven't fully understood this code yet: do you need to join the +> matching and non-matching authors and then split again for propertizing? +> It feels like it would be nicer to keep them separate and only combine +> at the very end. +> +> Does this all get nicer with your formatting search results series? + +Yes. I tried re-writing this code to use the already split authors here, +but given that I was going to re-write it for the formatting changes +anyway, I gave up. + +> +> Best wishes +> +> Mark +> +> +>> --- +>> emacs/notmuch.el | 64 +++++++++++++++++++++++++++++++------------------------- +>> 1 file changed, 35 insertions(+), 29 deletions(-) +>> +>> diff --git a/emacs/notmuch.el b/emacs/notmuch.el +>> index b44a907..688b37c 100644 +>> --- a/emacs/notmuch.el +>> +++ b/emacs/notmuch.el +>> @@ -672,22 +672,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 "") +>> @@ -703,9 +705,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) +>> @@ -721,20 +723,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. +>> @@ -768,8 +773,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.1 +>> +>> _______________________________________________ +>> notmuch mailing list +>> notmuch@notmuchmail.org +>> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2