emacs: Use async process helper for search

Previously, search started the async notmuch process directly.  Now,
it uses `notmuch-start-notmuch'.  This simplifies the process sentinel
a bit and means that we no longer have to worry about errors
interleaved with the JSON output.

We also update the tests of Emacs error handling, since the error
output is now separated from the search results buffer.
This commit is contained in:
Austin Clements 2013-05-31 20:40:05 -04:00 committed by David Bremner
parent a13b388243
commit 08fde50bf3
2 changed files with 37 additions and 18 deletions

View file

@ -653,15 +653,8 @@ of the result."
;; For version mismatch, there's no point in ;; For version mismatch, there's no point in
;; showing the search buffer ;; showing the search buffer
(when (or (= exit-status 20) (= exit-status 21)) (when (or (= exit-status 20) (= exit-status 21))
(kill-buffer)) (kill-buffer)
(condition-case err (throw 'return nil))
(notmuch-check-async-exit-status proc msg)
;; Suppress the error signal since strange
;; things happen if a sentinel signals. Mimic
;; the top-level's handling of error messages.
(error
(message "%s" (error-message-string err))
(throw 'return nil)))
(if (and atbob (if (and atbob
(not (string= notmuch-search-target-thread "found"))) (not (string= notmuch-search-target-thread "found")))
(set 'never-found-target-thread t))))) (set 'never-found-target-thread t)))))
@ -938,10 +931,9 @@ Other optional parameters are used as follows:
(erase-buffer) (erase-buffer)
(goto-char (point-min)) (goto-char (point-min))
(save-excursion (save-excursion
(let ((proc (start-process (let ((proc (notmuch-start-notmuch
"notmuch-search" buffer "notmuch-search" buffer #'notmuch-search-process-sentinel
notmuch-command "search" "search" "--format=json" "--format-version=1"
"--format=json" "--format-version=1"
(if oldest-first (if oldest-first
"--sort=oldest-first" "--sort=oldest-first"
"--sort=newest-first") "--sort=newest-first")
@ -951,7 +943,6 @@ Other optional parameters are used as follows:
;; should be called no matter how the process dies. ;; should be called no matter how the process dies.
(parse-buf (generate-new-buffer " *notmuch search parse*"))) (parse-buf (generate-new-buffer " *notmuch search parse*")))
(process-put proc 'parse-buf parse-buf) (process-put proc 'parse-buf parse-buf)
(set-process-sentinel proc 'notmuch-search-process-sentinel)
(set-process-filter proc 'notmuch-search-process-filter) (set-process-filter proc 'notmuch-search-process-filter)
(set-process-query-on-exit-flag proc nil)))) (set-process-query-on-exit-flag proc nil))))
(run-hooks 'notmuch-search-hook))) (run-hooks 'notmuch-search-hook)))

View file

@ -855,11 +855,10 @@ test_expect_success "Rendering HTML mail with images" \
'cat OUTPUT && grep -q smiley OUTPUT' 'cat OUTPUT && grep -q smiley OUTPUT'
test_begin_subtest "Search handles subprocess errors" test_begin_subtest "Search handles subprocess error exit codes"
cat > notmuch_fail <<EOF cat > notmuch_fail <<EOF
#!/bin/sh #!/bin/sh
echo This is output echo This is output
echo This is an error >&2
exit 1 exit 1
EOF EOF
chmod a+x notmuch_fail chmod a+x notmuch_fail
@ -876,8 +875,6 @@ sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\ test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
Error: Unexpected output from notmuch search: Error: Unexpected output from notmuch search:
This is output This is output
Error: Unexpected output from notmuch search:
This is an error
End of search results. End of search results.
--- ---
$PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details) $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)
@ -887,4 +884,35 @@ $PWD/notmuch_fail exited with status 1
command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox
exit status: 1" exit status: 1"
test_begin_subtest "Search handles subprocess warnings"
cat > notmuch_fail <<EOF
#!/bin/sh
echo This is output
echo This is a warning >&2
echo This is another warning >&2
exit 0
EOF
chmod a+x notmuch_fail
test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
(with-current-buffer \"*Messages*\" (erase-buffer))
(with-current-buffer \"*Notmuch errors*\" (erase-buffer))
(notmuch-search \"tag:inbox\")
(notmuch-test-wait)
(with-current-buffer \"*Messages*\"
(test-output \"MESSAGES\"))
(with-current-buffer \"*Notmuch errors*\"
(test-output \"ERROR\"))
(test-output))"
sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
Error: Unexpected output from notmuch search:
This is output
End of search results.
---
This is a warning (see *Notmuch errors* for more details)
---
[XXX]
This is a warning
This is another warning"
test_done test_done