[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2013-06-24 Thread Austin Clements
On Tue, 15 Nov 2011, Thomas Schwinge  wrote:
> Hi!
>
> On Thu, 10 Mar 2011 18:02:09 -0800, Carl Worth  wrote:
>> On Thu,  3 Feb 2011 00:56:39 +0100, Thomas Schwinge > schwinge.name> wrote:
>> > This issue has been lying in ambush as of 2009-11-24's commit
>> > 93af7b574598637c2766dd1f8ef343962c9a8efb.
>> 
>> Thanks very much for tracking down this bug, Thomas. What a nasty bug to
>> have in notmuch!
>> 
>> Your fix seems to drop the last thread from the search results
>> view. I've now committed a slightly modified fix that avoids that
>> problem. I also made the test case provide slightly cleaner results.
>> 
>> Let me know if you see any problems.
>
> That is much better, thanks!
>
> But we're not there yet...  %-| That is, today I hit another issue that
> appears to hide in the same elisp code.  See ``Error: Unexpected output
> From notmuch search''.  (And, thanks to eBay for long subject lines...)
>
> Unfortunately I'm totally out of time at the moment (final month of
> writing and wrapping up my diploma thesis), so I'm just dumping my state
> here, for now.

*snip*

I happened to notice that this is still marked as a bug.  I'm marking it
as fixed.  This code was completely rewritten to use the streaming JSON
parser (and now the streaming S-expression parser) and there's now a
test that feeds the process filter the search data one character at a
time to catch these sorts of buffer boundary bugs.


[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-11-15 Thread Thomas Schwinge
Hi!

On Thu, 10 Mar 2011 18:02:09 -0800, Carl Worth  wrote:
> On Thu,  3 Feb 2011 00:56:39 +0100, Thomas Schwinge  
> wrote:
> > This issue has been lying in ambush as of 2009-11-24's commit
> > 93af7b574598637c2766dd1f8ef343962c9a8efb.
> 
> Thanks very much for tracking down this bug, Thomas. What a nasty bug to
> have in notmuch!
> 
> Your fix seems to drop the last thread from the search results
> view. I've now committed a slightly modified fix that avoids that
> problem. I also made the test case provide slightly cleaner results.
> 
> Let me know if you see any problems.

That is much better, thanks!

But we're not there yet...  %-| That is, today I hit another issue that
appears to hide in the same elisp code.  See ``Error: Unexpected output


[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-03-10 Thread Carl Worth
On Thu, 3 Feb 2011 12:06:20 -0500, Austin Clements  wrote:
> Nice catch.
> 
> Is there a reason you keep the remaining data in a string instead of
> taking the more idiomatic elisp approach of leaving it in the process
> buffer?

Thomas is excused since he was just modifying my code originally.

And now I've gone and made it even worse by adding a bunch of hideously
non-idiomatic expressions like:

(while (and (< line (length string)) (= (elt string line) ?\n))
  (setq line (1+ line)))

The rough equivalent in C would be quite natural (where we actually have
pointers):

while (*s && *s == '\n')
s++;

but the above elisp is quite nasty.

> In fact, the code would probably be simpler if you
> immediately appended the string to the process buffer like a normal
> process-filter and then peeled things away using buffer-oriented
> regexp functions like looking-at.  Elisp is a lot better at
> manipulating buffers than it is at manipulating strings.

I spent a bit of time trying this. Using looking-at is definitely better
than string-match since we can then use things like (match-string 1)
rather than (match-string 1 string). And getting rid of the "line"
variable means that all of the ugly expressions like the one I showed
above went away.

The approach I tried was to use a temporary buffer for the unparsed data
and the process buffer for the resulting parsed data. The code got a bit
awkward as I kept having to jump back and for between (with-temp-buffer)
and (with-current-buffer buffer)---particularly due to the buffer-local
variable to hold the trailing data from the past run.

A better approach might be to use a single buffer, leave the unparse
data at the end, and just make it hidden.

But I'll leave this alone for now since fighting elisp has left me
annoyed. If anyone wants to clean up my hideous elisp here, then that
would be fine with me.

-Carl

-- 
carl.d.worth at intel.com
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-03-10 Thread Carl Worth
On Thu,  3 Feb 2011 00:56:39 +0100, Thomas Schwinge  
wrote:
> This issue has been lying in ambush as of 2009-11-24's commit
> 93af7b574598637c2766dd1f8ef343962c9a8efb.

Thanks very much for tracking down this bug, Thomas. What a nasty bug to
have in notmuch!

Your fix seems to drop the last thread from the search results
view. I've now committed a slightly modified fix that avoids that
problem. I also made the test case provide slightly cleaner results.

Let me know if you see any problems.

-Carl

-- 
carl.d.worth at intel.com
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-02-03 Thread Thomas Schwinge
Hallo!

On Thu, 3 Feb 2011 12:06:20 -0500, Austin Clements  wrote:
> Is there a reason you keep the remaining data in a string instead of
> taking the more idiomatic elisp approach of leaving it in the process
> buffer?  In fact, the code would probably be simpler if you
> immediately appended the string to the process buffer like a normal
> process-filter and then peeled things away using buffer-oriented
> regexp functions like looking-at.  Elisp is a lot better at
> manipulating buffers than it is at manipulating strings.

Ha, I hear you -- this is what I meant to do originally.  But then, the
save-in-string approach (even though I always considered keeping state in
the string a bit ugly) seemed more simple to me.  As I said: writing
elisp code is not my primary profession...  :-) (Perhaps I should buy a
book about it, or something.)  Now that you confirmed my original idea,
I'll see about re-writing the code accordingly, so thanks for the input!


Gr??e,
 Thomas
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: 



[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-02-03 Thread Austin Clements
Nice catch.

Is there a reason you keep the remaining data in a string instead of
taking the more idiomatic elisp approach of leaving it in the process
buffer?  In fact, the code would probably be simpler if you
immediately appended the string to the process buffer like a normal
process-filter and then peeled things away using buffer-oriented
regexp functions like looking-at.  Elisp is a lot better at
manipulating buffers than it is at manipulating strings.

On Wed, Feb 2, 2011 at 6:56 PM, Thomas Schwinge  wrote:
> This issue has been lying in ambush as of 2009-11-24's commit
> 93af7b574598637c2766dd1f8ef343962c9a8efb.
>
> Signed-off-by: Thomas Schwinge 
> ---
> ?emacs/notmuch.el | ? 70 +++--
> ?1 files changed, 41 insertions(+), 29 deletions(-)
>
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index 3d82f0d..35ccee6 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -641,9 +641,6 @@ non-authors is found, assume that all of the authors 
> match."
> ? ? (propertize authors 'face 'notmuch-search-matching-authors)))
>
> ?(defun notmuch-search-insert-authors (format-string authors)
> - ?;; Save the match data to avoid interfering with
> - ?;; `notmuch-search-process-filter'.
> - ?(save-match-data
> ? ? (let* ((formatted-authors (format format-string authors))
> ? ? ? ? ? (formatted-sample (format format-string ""))
> ? ? ? ? ? (visible-string formatted-authors)
> @@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors 
> match."
> ? ? ? ? ?(setq overlay (make-overlay start (point)))
> ? ? ? ? ?(overlay-put overlay 'invisible invis-spec)
> ? ? ? ? ?(overlay-put overlay 'isearch-open-invisible 
> #'notmuch-search-isearch-authors-show)))
> - ? ? ?(insert padding
> + ? ? ?(insert padding)))
>
> ?(defun notmuch-search-insert-field (field date count authors subject tags)
> ? (cond
> @@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors 
> match."
> ? ? ? ? ?do (notmuch-search-insert-field field date count authors subject 
> tags)))
> ? (insert "\n"))
>
> +(defvar notmuch-search-process-filter-data nil
> + ?"Data that has not yet been processed.")
> +(make-variable-buffer-local 'notmuch-search-process-filter-data)
> +
> ?(defun notmuch-search-process-filter (proc string)
> ? "Process and filter the output of \"notmuch search\""
> ? (let ((buffer (process-buffer proc))
> @@ -743,31 +744,41 @@ non-authors is found, assume that all of the authors 
> match."
> ? ? (if (buffer-live-p buffer)
> ? ? ? ?(with-current-buffer buffer
> ? ? ? ? ?(save-excursion
> - ? ? ? ? ? (let ((line 0)
> - ? ? ? ? ? ? ? ? (more t)
> - ? ? ? ? ? ? ? ? (inhibit-read-only t))
> - ? ? ? ? ? ? (while more
> - ? ? ? ? ? ? ? (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
> \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line)
> - ? ? ? ? ? ? ? ? ? (let* ((thread-id (match-string 1 string))
> - ? ? ? ? ? ? ? ? ? ? ? ? ?(date (match-string 2 string))
> - ? ? ? ? ? ? ? ? ? ? ? ? ?(count (match-string 3 string))
> - ? ? ? ? ? ? ? ? ? ? ? ? ?(authors (match-string 4 string))
> - ? ? ? ? ? ? ? ? ? ? ? ? ?(subject (match-string 5 string))
> - ? ? ? ? ? ? ? ? ? ? ? ? ?(tags (match-string 6 string))
> - ? ? ? ? ? ? ? ? ? ? ? ? ?(tag-list (if tags (save-match-data (split-string 
> tags)
> - ? ? ? ? ? ? ? ? ? ? (goto-char (point-max))
> - ? ? ? ? ? ? ? ? ? ? (let ((beg (point-marker)))
> - ? ? ? ? ? ? ? ? ? ? ? (notmuch-search-show-result date count authors 
> subject tags)
> - ? ? ? ? ? ? ? ? ? ? ? (notmuch-search-color-line beg (point-marker) 
> tag-list)
> - ? ? ? ? ? ? ? ? ? ? ? (put-text-property beg (point-marker) 
> 'notmuch-search-thread-id thread-id)
> - ? ? ? ? ? ? ? ? ? ? ? (put-text-property beg (point-marker) 
> 'notmuch-search-authors authors)
> - ? ? ? ? ? ? ? ? ? ? ? (put-text-property beg (point-marker) 
> 'notmuch-search-subject subject)
> - ? ? ? ? ? ? ? ? ? ? ? (if (string= thread-id notmuch-search-target-thread)
> - ? ? ? ? ? ? ? ? ? ? ? ? ? (progn
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? (set 'found-target beg)
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? (set 'notmuch-search-target-thread "found"
> - ? ? ? ? ? ? ? ? ? ? (set 'line (match-end 0)))
> - ? ? ? ? ? ? ? ? (set 'more nil)
> + ? ? ? ? ? (let ((inhibit-read-only t)
> + ? ? ? ? ? ? ? ? ;; We may have a partial line saved from the last iteration.
> + ? ? ? ? ? ? ? ? (string (concat notmuch-search-process-filter-data string))
> + ? ? ? ? ? ? ? ? (start 0))
> + ? ? ? ? ? ? (goto-char (point-max))
> + ? ? ? ? ? ? ;; Split `string' into lines.
> + ? ? ? ? ? ? (while (string-match "\n" string start)
> + ? ? ? ? ? ? ? (let ((line (substring string start (match-beginning 0
> + ? ? ? ? ? ? ? ? ;; Save the beginning of the next line already here, so that
> + ? ? ? ? ? ? ? ? ;; we can mangle the match data later on.
> + ? ? ? ? ? ? ? ? (setq start (match-end 0))
> + ? ? ? ? ? ? ? ? (if (string-match
> + ? ? ? ? ? ? ? ? ? ? ?"^\\(thread:[0-9A-Fa-f]*\\) 

[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-02-03 Thread Thomas Schwinge
This issue has been lying in ambush as of 2009-11-24's commit
93af7b574598637c2766dd1f8ef343962c9a8efb.

Signed-off-by: Thomas Schwinge 
---
 emacs/notmuch.el |   70 +++--
 1 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3d82f0d..35ccee6 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -641,9 +641,6 @@ non-authors is found, assume that all of the authors match."
 (propertize authors 'face 'notmuch-search-matching-authors)))

 (defun notmuch-search-insert-authors (format-string authors)
-  ;; Save the match data to avoid interfering with
-  ;; `notmuch-search-process-filter'.
-  (save-match-data
 (let* ((formatted-authors (format format-string authors))
   (formatted-sample (format format-string ""))
   (visible-string formatted-authors)
@@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors match."
  (setq overlay (make-overlay start (point)))
  (overlay-put overlay 'invisible invis-spec)
  (overlay-put overlay 'isearch-open-invisible 
#'notmuch-search-isearch-authors-show)))
-  (insert padding
+  (insert padding)))

 (defun notmuch-search-insert-field (field date count authors subject tags)
   (cond
@@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors 
match."
  do (notmuch-search-insert-field field date count authors subject 
tags)))
   (insert "\n"))

+(defvar notmuch-search-process-filter-data nil
+  "Data that has not yet been processed.")
+(make-variable-buffer-local 'notmuch-search-process-filter-data)
+
 (defun notmuch-search-process-filter (proc string)
   "Process and filter the output of \"notmuch search\""
   (let ((buffer (process-buffer proc))
@@ -743,31 +744,41 @@ non-authors is found, assume that all of the authors 
match."
 (if (buffer-live-p buffer)
(with-current-buffer buffer
  (save-excursion
-   (let ((line 0)
- (more t)
- (inhibit-read-only t))
- (while more
-   (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
\\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line)
-   (let* ((thread-id (match-string 1 string))
-  (date (match-string 2 string))
-  (count (match-string 3 string))
-  (authors (match-string 4 string))
-  (subject (match-string 5 string))
-  (tags (match-string 6 string))
-  (tag-list (if tags (save-match-data (split-string 
tags)
- (goto-char (point-max))
- (let ((beg (point-marker)))
-   (notmuch-search-show-result date count authors subject 
tags)
-   (notmuch-search-color-line beg (point-marker) tag-list)
-   (put-text-property beg (point-marker) 
'notmuch-search-thread-id thread-id)
-   (put-text-property beg (point-marker) 
'notmuch-search-authors authors)
-   (put-text-property beg (point-marker) 
'notmuch-search-subject subject)
-   (if (string= thread-id notmuch-search-target-thread)
-   (progn
- (set 'found-target beg)
- (set 'notmuch-search-target-thread "found"
- (set 'line (match-end 0)))
- (set 'more nil)
+   (let ((inhibit-read-only t)
+ ;; We may have a partial line saved from the last iteration.
+ (string (concat notmuch-search-process-filter-data string))
+ (start 0))
+ (goto-char (point-max))
+ ;; Split `string' into lines.
+ (while (string-match "\n" string start)
+   (let ((line (substring string start (match-beginning 0
+ ;; Save the beginning of the next line already here, so that
+ ;; we can mangle the match data later on.
+ (setq start (match-end 0))
+ (if (string-match
+  "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
\\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$"
+  line)
+ (let* ((thread-id (match-string 1 line))
+(date (match-string 2 line))
+(count (match-string 3 line))
+(authors (match-string 4 line))
+(subject (match-string 5 line))
+(tags (match-string 6 line))
+(tag-list (if tags (split-string tags
+   (let ((beg (point-marker)))
+ (notmuch-search-show-result date count authors 
subject tags)
+ 

[PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-02-03 Thread Thomas Schwinge
This issue has been lying in ambush as of 2009-11-24's commit
93af7b574598637c2766dd1f8ef343962c9a8efb.

Signed-off-by: Thomas Schwinge tho...@schwinge.name
---
 emacs/notmuch.el |   70 +++--
 1 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3d82f0d..35ccee6 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -641,9 +641,6 @@ non-authors is found, assume that all of the authors match.
 (propertize authors 'face 'notmuch-search-matching-authors)))
 
 (defun notmuch-search-insert-authors (format-string authors)
-  ;; Save the match data to avoid interfering with
-  ;; `notmuch-search-process-filter'.
-  (save-match-data
 (let* ((formatted-authors (format format-string authors))
   (formatted-sample (format format-string ))
   (visible-string formatted-authors)
@@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors match.
  (setq overlay (make-overlay start (point)))
  (overlay-put overlay 'invisible invis-spec)
  (overlay-put overlay 'isearch-open-invisible 
#'notmuch-search-isearch-authors-show)))
-  (insert padding
+  (insert padding)))
 
 (defun notmuch-search-insert-field (field date count authors subject tags)
   (cond
@@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors 
match.
  do (notmuch-search-insert-field field date count authors subject 
tags)))
   (insert \n))
 
+(defvar notmuch-search-process-filter-data nil
+  Data that has not yet been processed.)
+(make-variable-buffer-local 'notmuch-search-process-filter-data)
+
 (defun notmuch-search-process-filter (proc string)
   Process and filter the output of \notmuch search\
   (let ((buffer (process-buffer proc))
@@ -743,31 +744,41 @@ non-authors is found, assume that all of the authors 
match.
 (if (buffer-live-p buffer)
(with-current-buffer buffer
  (save-excursion
-   (let ((line 0)
- (more t)
- (inhibit-read-only t))
- (while more
-   (if (string-match ^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
\\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$ string line)
-   (let* ((thread-id (match-string 1 string))
-  (date (match-string 2 string))
-  (count (match-string 3 string))
-  (authors (match-string 4 string))
-  (subject (match-string 5 string))
-  (tags (match-string 6 string))
-  (tag-list (if tags (save-match-data (split-string 
tags)
- (goto-char (point-max))
- (let ((beg (point-marker)))
-   (notmuch-search-show-result date count authors subject 
tags)
-   (notmuch-search-color-line beg (point-marker) tag-list)
-   (put-text-property beg (point-marker) 
'notmuch-search-thread-id thread-id)
-   (put-text-property beg (point-marker) 
'notmuch-search-authors authors)
-   (put-text-property beg (point-marker) 
'notmuch-search-subject subject)
-   (if (string= thread-id notmuch-search-target-thread)
-   (progn
- (set 'found-target beg)
- (set 'notmuch-search-target-thread found
- (set 'line (match-end 0)))
- (set 'more nil)
+   (let ((inhibit-read-only t)
+ ;; We may have a partial line saved from the last iteration.
+ (string (concat notmuch-search-process-filter-data string))
+ (start 0))
+ (goto-char (point-max))
+ ;; Split `string' into lines.
+ (while (string-match \n string start)
+   (let ((line (substring string start (match-beginning 0
+ ;; Save the beginning of the next line already here, so that
+ ;; we can mangle the match data later on.
+ (setq start (match-end 0))
+ (if (string-match
+  ^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
\\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$
+  line)
+ (let* ((thread-id (match-string 1 line))
+(date (match-string 2 line))
+(count (match-string 3 line))
+(authors (match-string 4 line))
+(subject (match-string 5 line))
+(tags (match-string 6 line))
+(tag-list (if tags (split-string tags
+   (let ((beg (point-marker)))
+ (notmuch-search-show-result date count authors 
subject tags)
+ 

Re: [PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-02-03 Thread Austin Clements
Nice catch.

Is there a reason you keep the remaining data in a string instead of
taking the more idiomatic elisp approach of leaving it in the process
buffer?  In fact, the code would probably be simpler if you
immediately appended the string to the process buffer like a normal
process-filter and then peeled things away using buffer-oriented
regexp functions like looking-at.  Elisp is a lot better at
manipulating buffers than it is at manipulating strings.

On Wed, Feb 2, 2011 at 6:56 PM, Thomas Schwinge tho...@schwinge.name wrote:
 This issue has been lying in ambush as of 2009-11-24's commit
 93af7b574598637c2766dd1f8ef343962c9a8efb.

 Signed-off-by: Thomas Schwinge tho...@schwinge.name
 ---
  emacs/notmuch.el |   70 +++--
  1 files changed, 41 insertions(+), 29 deletions(-)

 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
 index 3d82f0d..35ccee6 100644
 --- a/emacs/notmuch.el
 +++ b/emacs/notmuch.el
 @@ -641,9 +641,6 @@ non-authors is found, assume that all of the authors 
 match.
     (propertize authors 'face 'notmuch-search-matching-authors)))

  (defun notmuch-search-insert-authors (format-string authors)
 -  ;; Save the match data to avoid interfering with
 -  ;; `notmuch-search-process-filter'.
 -  (save-match-data
     (let* ((formatted-authors (format format-string authors))
           (formatted-sample (format format-string ))
           (visible-string formatted-authors)
 @@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors 
 match.
          (setq overlay (make-overlay start (point)))
          (overlay-put overlay 'invisible invis-spec)
          (overlay-put overlay 'isearch-open-invisible 
 #'notmuch-search-isearch-authors-show)))
 -      (insert padding
 +      (insert padding)))

  (defun notmuch-search-insert-field (field date count authors subject tags)
   (cond
 @@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors 
 match.
          do (notmuch-search-insert-field field date count authors subject 
 tags)))
   (insert \n))

 +(defvar notmuch-search-process-filter-data nil
 +  Data that has not yet been processed.)
 +(make-variable-buffer-local 'notmuch-search-process-filter-data)
 +
  (defun notmuch-search-process-filter (proc string)
   Process and filter the output of \notmuch search\
   (let ((buffer (process-buffer proc))
 @@ -743,31 +744,41 @@ non-authors is found, assume that all of the authors 
 match.
     (if (buffer-live-p buffer)
        (with-current-buffer buffer
          (save-excursion
 -           (let ((line 0)
 -                 (more t)
 -                 (inhibit-read-only t))
 -             (while more
 -               (if (string-match ^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
 \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$ string line)
 -                   (let* ((thread-id (match-string 1 string))
 -                          (date (match-string 2 string))
 -                          (count (match-string 3 string))
 -                          (authors (match-string 4 string))
 -                          (subject (match-string 5 string))
 -                          (tags (match-string 6 string))
 -                          (tag-list (if tags (save-match-data (split-string 
 tags)
 -                     (goto-char (point-max))
 -                     (let ((beg (point-marker)))
 -                       (notmuch-search-show-result date count authors 
 subject tags)
 -                       (notmuch-search-color-line beg (point-marker) 
 tag-list)
 -                       (put-text-property beg (point-marker) 
 'notmuch-search-thread-id thread-id)
 -                       (put-text-property beg (point-marker) 
 'notmuch-search-authors authors)
 -                       (put-text-property beg (point-marker) 
 'notmuch-search-subject subject)
 -                       (if (string= thread-id notmuch-search-target-thread)
 -                           (progn
 -                             (set 'found-target beg)
 -                             (set 'notmuch-search-target-thread found
 -                     (set 'line (match-end 0)))
 -                 (set 'more nil)
 +           (let ((inhibit-read-only t)
 +                 ;; We may have a partial line saved from the last iteration.
 +                 (string (concat notmuch-search-process-filter-data string))
 +                 (start 0))
 +             (goto-char (point-max))
 +             ;; Split `string' into lines.
 +             (while (string-match \n string start)
 +               (let ((line (substring string start (match-beginning 0
 +                 ;; Save the beginning of the next line already here, so that
 +                 ;; we can mangle the match data later on.
 +                 (setq start (match-end 0))
 +                 (if (string-match
 +                      ^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) 
 \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$
 +              

Re: [PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines.

2011-02-03 Thread Thomas Schwinge
Hallo!

On Thu, 3 Feb 2011 12:06:20 -0500, Austin Clements amdra...@mit.edu wrote:
 Is there a reason you keep the remaining data in a string instead of
 taking the more idiomatic elisp approach of leaving it in the process
 buffer?  In fact, the code would probably be simpler if you
 immediately appended the string to the process buffer like a normal
 process-filter and then peeled things away using buffer-oriented
 regexp functions like looking-at.  Elisp is a lot better at
 manipulating buffers than it is at manipulating strings.

Ha, I hear you -- this is what I meant to do originally.  But then, the
save-in-string approach (even though I always considered keeping state in
the string a bit ugly) seemed more simple to me.  As I said: writing
elisp code is not my primary profession...  :-) (Perhaps I should buy a
book about it, or something.)  Now that you confirmed my original idea,
I'll see about re-writing the code accordingly, so thanks for the input!


Grüße,
 Thomas


pgpkcG4W4yhJj.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch