From: David Edmondson Date: Fri, 24 Oct 2014 17:44:02 +0000 (+0100) Subject: [PATCH v2 2/3] emacs: Improved display of matching/non-matching authors. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=79bcc3d51360cfb1ae7383da39373ca1c5f7de4e;p=notmuch-archives.git [PATCH v2 2/3] emacs: Improved display of matching/non-matching authors. --- diff --git a/9f/8dc4e00775126478ec5bf5b94dccf20a6449d3 b/9f/8dc4e00775126478ec5bf5b94dccf20a6449d3 new file mode 100644 index 000000000..ccf63287e --- /dev/null +++ b/9f/8dc4e00775126478ec5bf5b94dccf20a6449d3 @@ -0,0 +1,186 @@ +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 B6122429E29 + for ; Fri, 24 Oct 2014 10:44:19 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.699 +X-Spam-Level: +X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 + tests=[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 7pKTalzzxjNx for ; + Fri, 24 Oct 2014 10:44:14 -0700 (PDT) +Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com + [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 2F8CC431FD4 + for ; Fri, 24 Oct 2014 10:44:10 -0700 (PDT) +Received: by mail-wi0-f171.google.com with SMTP id em10so1835055wid.10 + for ; Fri, 24 Oct 2014 10:44:08 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:user-agent:from:to:subject:date:message-id + :in-reply-to:references; + bh=1QzqHNoTT+e5VIRb9bqb9Fbp8QK0Ume+uAAxTjqO3KY=; + b=iPE3gL4lxCGtaIvC0Nn84bOCyRjqsmb6xvTkvLubOlX2BvY8OrMYTE4Q6Tz8xaCau+ + 2dJL60F4VeFoeSbXE8zlPdO3NYhpX4yOjnQUteVbIoP01Aiug/hcaQO/VHAvf9InZqcg + HIzEKM10UYjYdBovzlbp8CTPHmEvATy8JA+zbS9Ly56FZDFKgLiF1SyVbNAr2s87vDmb + ULzh3nDfIGH9RC5xkGhslBhMW9E4x6Ns8NFNWIP+McAt3k07PG4M4g3IIQKxsKvUPcPd + 9d9ZnPPzDPT4/qsUDlk29+ehpm56fY8X6BAE30Q+OAmVD1PkdJpRJjHw5xQmreYYVyfX + CKew== +X-Gm-Message-State: + ALoCoQlYiVRaQVc9Ich2jDoB3aKeNx9OGfS00KoI95pV/I1hnZGG5+bdDY4W+urE3ZiCcIt17qe7 +X-Received: by 10.194.91.176 with SMTP id cf16mr6320061wjb.60.1414172648571; + Fri, 24 Oct 2014 10:44:08 -0700 (PDT) +Received: from disaster-area.hh.sledj.net + ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) + by mx.google.com with ESMTPSA id u8sm2718196wiz.14.2014.10.24.10.44.07 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Fri, 24 Oct 2014 10:44:07 -0700 (PDT) +Received: from localhost (30000@localhost [local]); + by localhost (OpenSMTPD) with ESMTPA id f60902d2; + for ; Fri, 24 Oct 2014 17:44:03 +0000 (UTC) +User-Agent: OpenSMTPD enqueuer (Demoostik) +From: David Edmondson +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/3] emacs: Improved display of matching/non-matching + authors. +Date: Fri, 24 Oct 2014 18:44:02 +0100 +Message-Id: <1414172643-28270-3-git-send-email-dme@dme.org> +X-Mailer: git-send-email 2.1.1 +In-Reply-To: <1414172643-28270-1-git-send-email-dme@dme.org> +References: <1414172643-28270-1-git-send-email-dme@dme.org> +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: Fri, 24 Oct 2014 17:44:20 -0000 + +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 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 +