This solves the problem due to the url-retrieve gotcha.
Main changes:
* Separation of the function to parse buffer and callback.
This is good because parsed data can be used from multiple
callbacks (SUCCESS and STATUS-CODE).
* As a result, current buffer for callbacks is not process
buffer anymore. Callbacks should not assume any particular
current buffer.
* RESPONSE-STATUS is added to the arguments for callbacks
to pass around the value of url-http-response-status.
Previous attempts:
* cb5f53c183:
Simpler and better fix than the previous one
* fff269fc39:
ein:notebooklist-delete-notebook works again
Previous fix ignores callbacks even if it is specified if the buffer
is killed. This is simply wrong. As the user of :STATUS-CODE
callback does not touch current buffer, I change the spec.
The bug was in ein:query-ajax-callback. When url-retrieve called in
its callback (which is the case of ein:notebooklist-delete-notebook),
same process buffer is reused. Therefore, old code killed another
buffer (namely notebook list buffer) by accident and the variable
url-http-response-status was void because it is outside of the process
buffer (I am not sure about this part). Current workaround is to
check if the buffer is live before executing buffer, using new macro
ein:with-live-buffer.
There was two bugs:
* Process buffer was killed in ein:notebooklist-url-retrieve-callback
where should be handled by ein:query-ajax-callback. There was two
calls of kill-buffer. This is why the list buffer was killed.
* At the time ein:query-ajax-cancel-timer is called in
ein:query-ajax-callback the current buffer was changed because
pop-to-buffer is called in the callback. Wrapping callbacks
with save-current-buffer fixes the problem.
This change adds timeout to notebook-save-notebook. This is useful
since sometimes Emacs does not start transaction and have opened
process hanging around.
This change also fixes a bug which might be occurred in the previous
version: ein:notebook-discard-output-p is called from
ein:notebook-save-notebook via ein:notebook-to-json but not on the
notebook buffer. This function access to the buffer, but not treated
properly. This change fixes this problem.