Also update the default code context for completion requests to be the current
line up to `point`.
This allows completion in python kernels to work as expected. Previously when
sending the whole line, the python completer would not return expected results.
For example, if you had something like
os.mkdir(os.path.|, 0777)
then you would not receive any completions for the os.path namespace, only for
the global namespace.
Also move the function to jupyter-client.el from jupyter-repl.el
* jupyter-repl.el (jupyter-repl-display-traceback): Do it.
* jupyter-client.el (jupyter-display-traceback): Do it.
`jupyter-iopub-message-hook` is called in a channel's `jupyter-handle-message`
method, but setting the execution state should be independent of the value of
`jupyter-inhibit-handlers. So move setting the execution state into the
client's `jupyter-handle-message` method.
It still sometimes isn't caught but it is more reliable. This mainly affects
testing.
* jupyter-client.el (jupyter-start-channels): Add a small delay after starting
channels.
* jupyter-kernel-manager.el (jupyter-start-kernel): Remove superfluous delay.
* jupyter-client.el (initialize-instance): Stop channels in finalizer.
* jupyter-ioloop.el (jupyter-ioloop--make-filter): New function.
(jupyter-ioloop-start): Make a weak reference OBJECT.
This is needed as opposed to eieio-instance-tracker so that we can create weak
references to objects. We don't want to have to manually delete an instance.
* jupyter-base.el (jupyter-instance-tracker): Do it.
(jupyter-all-objects): New function.
* jupyter-client.el (jupyter--clients): New variable.
(jupyter-kernel-client): Inherit from new class.
(jupyter-clients): Use jupyter-all-objects.
* jupyter-kernel-manager.el (jupyter-kernel-managers): New function.
* jupyter-base.el (jupyter-default-timeout)
(jupyter-long-timeout): Moved from jupyter-client.el
(jupyter-with-timeout): Do it.
* jupyter-client.el (jupyter-wait-until): Use it.
* jupyter-kernel-manager.el (jupyter-shutdown-kernel)
(jupyter-interrupt-kernel, jupyter-start-new-kernel):
(jupyter-start-kernel): Use it.
use timeout
* jupyter-client.el (jupyter-kernel-client): Do it.
(jupyter-run-hook-with-args-until-success): Pass client as first argument to
hooks.
(jupyter-execution-state): New convenience function.
(jupyter--set-execution-state): New helper function. Add as global IOPUB
message hook to set the execution-state slot.
* jupyter-repl.el (jupyter-repl-client): Remove execution-state slot.
(jupyter-handle-status): Don't set the execution-state slot.
(jupyter-repl-ret, jupyter-repl-interaction-mode-line): Use
jupyter-execution-state.
(jupyter-repl-initialize-hooks): Take into account changes to message hooks.
* jupyter-kernel-manager (jupyter-start-new-kernel): Update callback.
* jupyter-client.el (jupyter--run-callbacks): Simplify.
(jupyter--set-callback): New macro.
(jupyter--add-callback): Use new macro.
(jupyter-add-callback): Make more readable.
callbacks
* jupyter-client.el (jupyter-initialize-connection):
Stop channels if any are running.
Fix wrong usage of collect when constructing channel plist.
(jupyter-ioloop-handler): Remove usage of `with-slots` when a slot is only
accessed once.
(jupyter-start-channel, jupyter-stop-channel): Split waiting for channel to
start/stop into an :after method. Verify CHANNEL argument is valid.
This is necessary to allow for the `jupyter-lang' method specializer to work in
contexts other than the REPL buffer, such as in an `org-mode` buffer when
handling `jupyter-org-request' objects.
* jupyter-client.el (jupyter-handle-message): (CLIENT ...) Do it.
* jupyter-org-client.el (jupyter-org-add-result):
Don't let bind `jupyter-current-client`.
Remove CLIENT argument. Update all callers.
This commit extracts out the IOLoop functions which are used to define an
IOLoop that send and receive messages on Jupyter channels into is own object.
* jupyter-channel-ioloop.el: New file.
(jupyter-channel-ioloop): A sub-type of `jupyter-ioloop` that sets up an IOLoop
to send/receive messages on Jupyter channels.
(jupyter-ioloop-channels):
(jupyter-ioloop-session): New variables used in `jupyter-channel-ioloop`
events.
(jupyter-ioloop-add-arg-type jupyter-channel): Moved from `jupyter-client.el`.
(jupyter-channel-ioloop-add-session): New function.
(jupyter-ioloop-start): Setup ioloop to communicate with Jupyter channels.
(jupyter-channel-ioloop-recv-messages):
(jupyter-channel-ioloop-add-start-channel-event):
(jupyter-channel-ioloop-add-stop-channel-event):
(jupyter-channel-ioloop-add-send-event): Moved from `jupyter-client.el`,
replaced jupyter-ioloop prefix with jupyter-channel-ioloop.
* jupyter-client.el: Require `jupyter-channel-ioloop` instead of
`jupyter-ioloop`.
(jupyter-kernel-client): Change type of `ioloop` to `jupyter-channel-ioloop`.
(jupyter-client--ioloop-setup-form): Remove.
(jupyter-ioloop-add-arg-type jupyter-channel): Move to
`jupyter-channel-ioloop.el`.
(jupyter-ioloop-add-start-channel-event):
(jupyter-ioloop-add-stop-channel-event):
(jupyter-ioloop-add-send-event): Move to `jupyter-channel-ioloop.el`, replace
jupyter-ioloop prefix with jupyter-channel-ioloop.
(jupyter-ioloop-start): Remove.
(jupyter-start-channels): Ensure `jupyter-ioloop-start` method of
`jupyter-channel-ioloop` is called. Set ioloop process buffer to `-buffer` slot
of client.
* jupyter-ioloop.el (jupyter-ioloop-start): Remove :before method.
A `jupyter-kernel-client' defers most of its message sending, receiving, and
message processing to a subprocess which sends its messages to the kernel
through zmq sockets and polls for any messages to received from the kernel.
This commit generalizes this by introducing a new `jupyter-ioloop` type which
encapsulates the subprocess and the code necessary to build up the function
that does the work of communicating with a kernel in the subprocess
environment.
* jupyter-channels.el: Remove `jupyter-async-channel`
* jupyter-ioloop.el: New file.
(jupyter-ioloop-poller):
(jupyter-ioloop-nsockets):
(jupyter-ioloop-pre-hook):
(jupyter-ioloop-post-hook):
(jupyter-ioloop--argument-types): New variables.
(jupyter-ioloop): New function to create `jupyter-ioloop` objects.
(jupyter-ioloop-add-setup):
(jupyter-ioloop-add-teardown):
(jupyter-ioloop-add-arg-type):
(jupyter-ioloop-add-event): New macros.
(jupyter-ioloop-handler):
(jupyter-ioloop-add-callback):
(jupyter-ioloop-start):
(jupyter-ioloop-stop): New methods.
(jupyter-send): Method addition for `jupyter-ioloop` objects.
(jupyter-ioloop-wait-until): Moved function from `jupyter-client.el`, changed
argument order.
(jupyter-ioloop--replace-args):
(jupyter-ioloop--event-dispatcher):
(jupyter-ioloop--function):
(jupyter-ioloop--filter):
(jupyter-ioloop--sentinel): Helper functions.
* jupyter-client.el: Add `jupyter-ioloop` require.
Remove `jupyter-shell-channel`, `jupyter-iopub-channel`,
`jupyter-stdin-channel` classes.
(jupyter-kernel-client): Change type of `ioloop` slot to `jupyter-ioloop`,
remove `shell-channel`, iopub-channel`, `stdin-channel`, and `hb-channel`
slots. Add `channels` slot.
(jupyter-initialize-connection): Replace channel initialization with
initialization of new `channels` slot.
(jupyter-send): Add better assertion. Call an ioloop's `jupyter-send` method.
Expect a Jupyter channel keyword as the `channel` argument.
(jupyter--ioloop-do-command):
(jupyter--ioloop-with-lock-file):
(jupyter--ioloop-unlock):
(jupyter--ioloop-lock):
(jupyter--ioloop):
(jupyter--ioloop-sentinel):
(jupyter--get-channel):
(jupyter--ioloop-filter):
(jupyter--start-ioloop): Remove functions/macros.
(jupyter-ioloop-wait-until): Move to `jupyter-ioloop.el`
(jupyter-hb-pause):
(jupyter-hb-unpause):
(jupyter-hb-beating-p): Use `channels` slot.
(jupyter-client--ioloop-setup-form): New constant.
(jupyter-ioloop-add-arg-type): New jupyter-channel argument type.
(jupyter-ioloop-add-start-channel-event):
(jupyter-ioloop-add-stop-channel-event):
(jupyter-ioloop-add-send-event): New `jupyter-ioloop` event types for clients.
(jupyter-ioloop-start):
(jupyter-ioloop-handler): Method additions specializing to
`jupyter-kernel-client`s.
(jupyter-start-channel):
(jupyter-stop-channel):
(jupyter-channel-alive-p): Method additions for a client utilizing `channels` slot.
(jupyter-start-channels):
(jupyter-stop-channels):
(jupyter-channels-running-p): Use new `jupyter-ioloop` interface and channel
methods.
(jupyter-handle-message): (`jupyter-kernel-client` method) Add new `msg`
argument. Remove call to `jupyter-get-message`.
(jupyter-handle-message): (All channel methods) Replace
`jupyter-stdin-channel`, `jupyter-iopub-channel`, and `jupyter-shell-channel`
with `(eql :stdin)`, `(eql :iopub)`, and `(eql :shell)`
(jupyter-handle-input-request):
(jupyter-send-execute-request):
(jupyter-send-inspect-request):
(jupyter-send-complete-request):
(jupyter-send-history-request):
(jupyter-send-is-complete-request):
(jupyter-send-comm-info-request):
(jupyter-send-comm-open):
(jupyter-send-comm-msg):
(jupyter-send-comm-close):
(jupyter-sned-kernel-info-request):
(jupyter-send-shutdown-request): Remove uses of `shell-channel` and
`stdin-channel` slot. Pass in expected channel keyword as the `channel`
argument in the call to `jupyter-send`
Previously pending requests were associated with the ioloop process itself, but
pending requests are a particular feature of the client and used only for a
client's purpose.