As this command requires to invoke multi-line python code, ein.py is
added to store python code needed for EIN. The sys.path is added
automatically when the kernel is started so that any function can be
called as ``__import__("ein").FUNCTION()``. This way, namespace is
not contaminated at all.
Another possible way to implement this is to use user_expressions.
However, replied message is Python's repr. As there is no reliable
way to convert it except using Python itself, I am using stream to
get CWD.
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.