Re: notmuch-search-toggle-order and notmuch-tree
[notmuch-archives.git] / 1f / 1bc1b903fcc93e1965cb5990edbc85fbd8ac72
1 Return-Path: <tomi.ollila@iki.fi>\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 328D8431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 08:20:36 -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 tests=[none]\r
12         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 VIUcT5yPPs95 for <notmuch@notmuchmail.org>;\r
16         Sat, 15 Dec 2012 08:20:35 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 650AB431FB6\r
19         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 08:20:35 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 78A7310007E;\r
22         Sat, 15 Dec 2012 18:20:30 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 1/7] emacs: Centralize notmuch command error handling\r
26 In-Reply-To: <1355548513-10085-2-git-send-email-amdragon@mit.edu>\r
27 References: <1355548513-10085-1-git-send-email-amdragon@mit.edu>\r
28         <1355548513-10085-2-git-send-email-amdragon@mit.edu>\r
29 User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Sat, 15 Dec 2012 18:20:30 +0200\r
35 Message-ID: <m2obhvp9rl.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\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: Sat, 15 Dec 2012 16:20:36 -0000\r
51 \r
52 On Sat, Dec 15 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
53 \r
54 > This provides library functions for unified handling of errors from\r
55 > the notmuch CLI.  Follow-up patches will convert some scattered error\r
56 > handling to use this and add error handling where we currently ignore\r
57 > errors.\r
58 > ---\r
59 \r
60 The series looks pretty good, some hardcoded patchs Mark noticed\r
61 and it looks to me (after viewing id:8738z7hd6x.fsf@qmul.ac.uk\r
62 that err -> nil could be done.\r
63 \r
64 Would (goto-char (point-min)) be needed before (insert msg) in\r
65 this patch -- what If user has moved cursor while viewing old\r
66 error messages but not pressed q (dismissed) on the buffer. \r
67 Also, what about (unless (eobp) (insert "\n")) to add empty\r
68 line between error messages ?\r
69 \r
70 Tomi\r
71 \r
72 >  emacs/notmuch-lib.el |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
73 >  1 file changed, 53 insertions(+)\r
74 >\r
75 > diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
76 > index 9c4ee71..851098f 100644\r
77 > --- a/emacs/notmuch-lib.el\r
78 > +++ b/emacs/notmuch-lib.el\r
79 > @@ -316,6 +316,59 @@ string), a property list of face attributes, or a list of these."\r
80 >       (put-text-property pos next 'face (cons face cur))\r
81 >       (setq pos next)))))\r
82 >  \r
83 > +(defun notmuch-pop-up-error (msg)\r
84 > +  "Pop up an error buffer displaying MSG.\r
85 > +\r
86 > +This will accumulate error messages in the errors buffer until\r
87 > +the user dismisses it."\r
88 > +\r
89 > +  (let ((buf (get-buffer-create "*Notmuch errors*")))\r
90 > +    (with-current-buffer buf\r
91 > +      (view-mode-enter nil #'kill-buffer)\r
92 > +      (let ((inhibit-read-only t))\r
93 > +     (insert msg)\r
94 > +     (unless (bolp)\r
95 > +       (insert "\n"))\r
96 > +     (goto-char (point-min))))\r
97 > +    (pop-to-buffer buf)))\r
98 > +\r
99 > +(defun notmuch-check-exit-status (exit-status command &optional output err-file)\r
100 > +  "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.\r
101 > +\r
102 > +If EXIT-STATUS is non-zero, pop up a notmuch error buffer\r
103 > +describing the error and signal an Elisp error.  EXIT-STATUS must\r
104 > +be a number indicating the exit status code of a process or a\r
105 > +string describing the signal that terminated the process (such as\r
106 > +returned by `call-process').  COMMAND must be a list giving the\r
107 > +command and its arguments.  OUTPUT, if provided, is a string\r
108 > +giving the output of command.  ERR-FILE, if provided, is the name\r
109 > +of a file containing the error output of command.  OUTPUT and the\r
110 > +contents of ERR-FILE will be included in the error message."\r
111 > +\r
112 > +  ;; This is implemented as a cond to make it easy to expand.\r
113 > +  (cond\r
114 > +   ((eq exit-status 0) t)\r
115 > +   (t\r
116 > +    (notmuch-pop-up-error\r
117 > +     (concat\r
118 > +      (format "Error invoking notmuch.  %s exited with %s%s.\n"\r
119 > +           (mapconcat #'identity command " ")\r
120 > +           ;; Signal strings look like "Terminated", hence the\r
121 > +           ;; colon.\r
122 > +           (if (integerp exit-status) "status " "signal: ")\r
123 > +           exit-status)\r
124 > +      (when err-file\r
125 > +     (concat "Error:\n"\r
126 > +             (with-temp-buffer\r
127 > +               (insert-file-contents err-file)\r
128 > +               (if (eobp)\r
129 > +                   "(no error output)\n"\r
130 > +                 (buffer-string)))))\r
131 > +      (when (and output (not (equal output "")))\r
132 > +     (format "Output:\n%s" output))))\r
133 > +    ;; Mimic `process-lines'\r
134 > +    (error "%s exited with status %s" (car command) exit-status))))\r
135 > +\r
136 >  ;; Compatibility functions for versions of emacs before emacs 23.\r
137 >  ;;\r
138 >  ;; Both functions here were copied from emacs 23 with the following copyright:\r
139 > -- \r
140 > 1.7.10.4\r
141 >\r
142 > _______________________________________________\r
143 > notmuch mailing list\r
144 > notmuch@notmuchmail.org\r
145 > http://notmuchmail.org/mailman/listinfo/notmuch\r