Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / b6 / 68954d94304965ba1e8bf2eca52babd152b7e3
1 Return-Path: <dme@dme.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1130A4196F0\r
6         for <notmuch@notmuchmail.org>; Tue,  4 May 2010 03:54:59 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id H5TZcjKK4OXp for <notmuch@notmuchmail.org>;\r
16         Tue,  4 May 2010 03:54:58 -0700 (PDT)\r
17 Received: from mail-ww0-f53.google.com (mail-ww0-f53.google.com\r
18  [74.125.82.53])        by olra.theworths.org (Postfix) with ESMTP id 07A40431FC1       for\r
19  <notmuch@notmuchmail.org>; Tue,  4 May 2010 03:54:57 -0700 (PDT)\r
20 Received: by wwd20 with SMTP id 20so1043604wwd.26\r
21         for <notmuch@notmuchmail.org>; Tue, 04 May 2010 03:54:57 -0700 (PDT)\r
22 Received: by 10.227.133.19 with SMTP id d19mr935779wbt.144.1272970496156;\r
23         Tue, 04 May 2010 03:54:56 -0700 (PDT)\r
24 Received: from ut.hh.sledj.net (gmp-ea-fw-1.sun.com [192.18.1.36])\r
25         by mx.google.com with ESMTPS id y23sm2949480wby.22.2010.05.04.03.54.54\r
26         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
27         Tue, 04 May 2010 03:54:54 -0700 (PDT)\r
28 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
29         id 131D2594121; Tue,  4 May 2010 11:55:34 +0100 (BST)\r
30 From: David Edmondson <dme@dme.org>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH] emacs: In search mode, truncate authors using invisible text.\r
33 Date: Tue,  4 May 2010 11:55:28 +0100\r
34 Message-Id: <1272970528-7893-1-git-send-email-dme@dme.org>\r
35 X-Mailer: git-send-email 1.7.0\r
36 In-Reply-To: <87ljc0k9xk.fsf@yoom.home.cworth.org>\r
37 References: <87ljc0k9xk.fsf@yoom.home.cworth.org>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Tue, 04 May 2010 10:54:59 -0000\r
51 \r
52 Rather than discarding authors when truncated to fit the defined\r
53 column width, mark the text beyond the end of the column as invisible\r
54 and allow `isearch' to be used over the text so hidden.\r
55 \r
56 This allows us to retain the compact display whilst enabling a user to\r
57 find the elided text.\r
58 ---\r
59  emacs/notmuch.el |   61 +++++++++++++++++++++++++++++++++++++++--------------\r
60  1 files changed, 45 insertions(+), 16 deletions(-)\r
61 \r
62 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
63 index c2fefe5..10babe4 100644\r
64 --- a/emacs/notmuch.el\r
65 +++ b/emacs/notmuch.el\r
66 @@ -608,23 +608,52 @@ matching will be applied."\r
67                   (t\r
68                    (setq tags-faces (cdr tags-faces)))))))))\r
69  \r
70 +(defun notmuch-search-isearch-authors-show (overlay)\r
71 +  (remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))\r
72 +\r
73  (defun notmuch-search-insert-authors (format-string authors)\r
74 -  (insert (let* ((formatted-sample (format format-string ""))\r
75 -                (formatted-authors (format format-string authors))\r
76 -                (truncated-string\r
77 -                 (if (> (length formatted-authors)\r
78 -                        (length formatted-sample))\r
79 -                     (concat (substring authors 0 (- (length formatted-sample) 4)) "... ")\r
80 -                   formatted-authors)))\r
81 -           ;; Need to save the match data to avoid interfering with\r
82 -           ;; `notmuch-search-process-filter'.\r
83 -           (save-match-data\r
84 -             (if (string-match "\\(.*\\)|\\(..*\\)" truncated-string)\r
85 -                 (concat (propertize (concat (match-string 1 truncated-string) ",")\r
86 -                                     'face 'notmuch-search-matching-authors)\r
87 -                         (propertize (match-string 2 truncated-string)\r
88 -                                     'face 'notmuch-search-non-matching-authors))\r
89 -               (propertize truncated-string 'face 'notmuch-search-matching-authors))))))\r
90 +  (let* ((propertized-authors\r
91 +         ;; Need to save the match data to avoid interfering with\r
92 +         ;; `notmuch-search-process-filter'.\r
93 +         (save-match-data\r
94 +           ;; Authors that don't match the search query are shown in a\r
95 +           ;; different font.\r
96 +           (if (string-match "\\(.*\\)|\\(..*\\)" authors)\r
97 +               (concat (propertize (concat (match-string 1 authors) ",")\r
98 +                                   'face 'notmuch-search-matching-authors)\r
99 +                       (propertize (match-string 2 authors)\r
100 +                                   'face 'notmuch-search-non-matching-authors))\r
101 +             (propertize authors 'face 'notmuch-search-matching-authors))))\r
102 +\r
103 +        (formatted-sample (format format-string ""))\r
104 +        (formatted-authors (format format-string propertized-authors))\r
105 +        visible-string invisible-string)\r
106 +\r
107 +    ;; Determine the part of the authors that will be visible by\r
108 +    ;; default.\r
109 +    (if (> (length formatted-authors)\r
110 +          (length formatted-sample))\r
111 +       ;; 4 is `(length "... ")'.\r
112 +       (let ((visible-length (- (length formatted-sample) 4)))\r
113 +         (setq visible-string (substring propertized-authors 0 visible-length)\r
114 +               invisible-string (substring propertized-authors visible-length)))\r
115 +      (setq visible-string formatted-authors\r
116 +           invisible-string nil))\r
117 +\r
118 +    ;; Insert both the visible and invisible author strings.\r
119 +    (insert visible-string)\r
120 +    (when invisible-string\r
121 +      (let ((start (point))\r
122 +           (invis-spec (make-symbol "notmuch-search-authors"))\r
123 +           overlay)\r
124 +       (insert invisible-string)\r
125 +       ;; Using a cons-cell here causes an ellipsis to be inserted\r
126 +       ;; instead of the invisible text.\r
127 +       (add-to-invisibility-spec (cons invis-spec t))\r
128 +       (setq overlay (make-overlay start (point)))\r
129 +       (overlay-put overlay 'invisible invis-spec)\r
130 +       (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show)\r
131 +       (insert " ")))))\r
132  \r
133  (defun notmuch-search-insert-field (field date count authors subject tags)\r
134    (cond\r
135 -- \r
136 1.7.0\r
137 \r