Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 64 / db2d359e3d521d00a100df53a417b0706566ac
1 Return-Path: <thomas@schwinge.name>\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 6DF2F431FB6\r
6         for <notmuch@notmuchmail.org>; Wed,  2 Feb 2011 15:57:31 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\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 7blhMd43mQ7x for <notmuch@notmuchmail.org>;\r
16         Wed,  2 Feb 2011 15:57:30 -0800 (PST)\r
17 Received: from smtprelay03.ispgateway.de (smtprelay03.ispgateway.de\r
18         [80.67.18.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 35D69431FB5\r
20         for <notmuch@notmuchmail.org>; Wed,  2 Feb 2011 15:57:30 -0800 (PST)\r
21 Received: from [87.180.46.33] (helo=stokes.schwinge.homeip.net)\r
22         by smtprelay03.ispgateway.de with esmtpa (Exim 4.68)\r
23         (envelope-from <thomas@schwinge.name>) id 1PkmZk-0000PV-TZ\r
24         for notmuch@notmuchmail.org; Thu, 03 Feb 2011 00:57:29 +0100\r
25 Received: (qmail 7034 invoked from network); 2 Feb 2011 23:57:12 -0000\r
26 Received: from schwinge.homeip.net (87.180.46.33)\r
27         by stokes.schwinge.homeip.net with QMQP; 2 Feb 2011 23:57:12 -0000\r
28 Received: (nullmailer pid 16862 invoked by uid 1000);\r
29         Wed, 02 Feb 2011 23:57:11 -0000\r
30 From: Thomas Schwinge <thomas@schwinge.name>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope\r
33         with incomplete lines.\r
34 Date: Thu,  3 Feb 2011 00:56:39 +0100\r
35 Message-Id: <1296690999-16542-3-git-send-email-thomas@schwinge.name>\r
36 X-Mailer: git-send-email 1.7.1\r
37 In-Reply-To: <87zkqeiffj.fsf@kepler.schwinge.homeip.net>\r
38 References: <87zkqeiffj.fsf@kepler.schwinge.homeip.net>\r
39 X-Df-Sender: thomas@schwinge.name\r
40 Cc: Thomas Schwinge <thomas@schwinge.name>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Wed, 02 Feb 2011 23:57:31 -0000\r
54 \r
55 This issue has been lying in ambush as of 2009-11-24's commit\r
56 93af7b574598637c2766dd1f8ef343962c9a8efb.\r
57 \r
58 Signed-off-by: Thomas Schwinge <thomas@schwinge.name>\r
59 ---\r
60  emacs/notmuch.el |   70 +++++++++++++++++++++++++++++++----------------------\r
61  1 files changed, 41 insertions(+), 29 deletions(-)\r
62 \r
63 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
64 index 3d82f0d..35ccee6 100644\r
65 --- a/emacs/notmuch.el\r
66 +++ b/emacs/notmuch.el\r
67 @@ -641,9 +641,6 @@ non-authors is found, assume that all of the authors match."\r
68      (propertize authors 'face 'notmuch-search-matching-authors)))\r
69  \r
70  (defun notmuch-search-insert-authors (format-string authors)\r
71 -  ;; Save the match data to avoid interfering with\r
72 -  ;; `notmuch-search-process-filter'.\r
73 -  (save-match-data\r
74      (let* ((formatted-authors (format format-string authors))\r
75            (formatted-sample (format format-string ""))\r
76            (visible-string formatted-authors)\r
77 @@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors match."\r
78           (setq overlay (make-overlay start (point)))\r
79           (overlay-put overlay 'invisible invis-spec)\r
80           (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show)))\r
81 -      (insert padding))))\r
82 +      (insert padding)))\r
83  \r
84  (defun notmuch-search-insert-field (field date count authors subject tags)\r
85    (cond\r
86 @@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors match."\r
87           do (notmuch-search-insert-field field date count authors subject tags)))\r
88    (insert "\n"))\r
89  \r
90 +(defvar notmuch-search-process-filter-data nil\r
91 +  "Data that has not yet been processed.")\r
92 +(make-variable-buffer-local 'notmuch-search-process-filter-data)\r
93 +\r
94  (defun notmuch-search-process-filter (proc string)\r
95    "Process and filter the output of \"notmuch search\""\r
96    (let ((buffer (process-buffer proc))\r
97 @@ -743,31 +744,41 @@ non-authors is found, assume that all of the authors match."\r
98      (if (buffer-live-p buffer)\r
99         (with-current-buffer buffer\r
100           (save-excursion\r
101 -           (let ((line 0)\r
102 -                 (more t)\r
103 -                 (inhibit-read-only t))\r
104 -             (while more\r
105 -               (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line)\r
106 -                   (let* ((thread-id (match-string 1 string))\r
107 -                          (date (match-string 2 string))\r
108 -                          (count (match-string 3 string))\r
109 -                          (authors (match-string 4 string))\r
110 -                          (subject (match-string 5 string))\r
111 -                          (tags (match-string 6 string))\r
112 -                          (tag-list (if tags (save-match-data (split-string tags)))))\r
113 -                     (goto-char (point-max))\r
114 -                     (let ((beg (point-marker)))\r
115 -                       (notmuch-search-show-result date count authors subject tags)\r
116 -                       (notmuch-search-color-line beg (point-marker) tag-list)\r
117 -                       (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id)\r
118 -                       (put-text-property beg (point-marker) 'notmuch-search-authors authors)\r
119 -                       (put-text-property beg (point-marker) 'notmuch-search-subject subject)\r
120 -                       (if (string= thread-id notmuch-search-target-thread)\r
121 -                           (progn\r
122 -                             (set 'found-target beg)\r
123 -                             (set 'notmuch-search-target-thread "found"))))\r
124 -                     (set 'line (match-end 0)))\r
125 -                 (set 'more nil)))))\r
126 +           (let ((inhibit-read-only t)\r
127 +                 ;; We may have a partial line saved from the last iteration.\r
128 +                 (string (concat notmuch-search-process-filter-data string))\r
129 +                 (start 0))\r
130 +             (goto-char (point-max))\r
131 +             ;; Split `string' into lines.\r
132 +             (while (string-match "\n" string start)\r
133 +               (let ((line (substring string start (match-beginning 0))))\r
134 +                 ;; Save the beginning of the next line already here, so that\r
135 +                 ;; we can mangle the match data later on.\r
136 +                 (setq start (match-end 0))\r
137 +                 (if (string-match\r
138 +                      "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$"\r
139 +                      line)\r
140 +                     (let* ((thread-id (match-string 1 line))\r
141 +                            (date (match-string 2 line))\r
142 +                            (count (match-string 3 line))\r
143 +                            (authors (match-string 4 line))\r
144 +                            (subject (match-string 5 line))\r
145 +                            (tags (match-string 6 line))\r
146 +                            (tag-list (if tags (split-string tags))))\r
147 +                       (let ((beg (point-marker)))\r
148 +                         (notmuch-search-show-result date count authors subject tags)\r
149 +                         (notmuch-search-color-line beg (point-marker) tag-list)\r
150 +                         (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id)\r
151 +                         (put-text-property beg (point-marker) 'notmuch-search-authors authors)\r
152 +                         (put-text-property beg (point-marker) 'notmuch-search-subject subject)\r
153 +                         (if (string= thread-id notmuch-search-target-thread)\r
154 +                             (setq found-target beg\r
155 +                                   notmuch-search-target-thread "found"))))\r
156 +                   ;; Non-conforming line.\r
157 +                   (insert (concat "Non-conforming line (ignored): <" line ">.\n")))))\r
158 +             ;; Save the remainder after the last line break for the next\r
159 +             ;; interation.\r
160 +             (setq notmuch-search-process-filter-data (substring string start))))\r
161           (if found-target\r
162               (goto-char found-target)))\r
163        (delete-process proc))))\r
164 @@ -858,6 +869,7 @@ The optional parameters are used as follows:\r
165                        "--sort=newest-first")\r
166                      query)))\r
167           (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
168 +         (setq notmuch-search-process-filter-data nil)\r
169           (set-process-filter proc 'notmuch-search-process-filter))))\r
170      (run-hooks 'notmuch-search-hook)))\r
171  \r
172 -- \r
173 1.7.1\r
174 \r