Commit graph

269 commits

Author SHA1 Message Date
Nathaniel Nicandro
c0e47165a9 Add instance tracker class
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.
2018-11-15 23:04:25 -06:00
Nathaniel Nicandro
134f84a59c Add object finalizer class
* jupyter-base.el (jupyter-finalized-object): New class.
(initialize-instance): New method addition.
(jupyter-add-finalizer): New method.

* jupyter-client.el (jupyter-kernel-client):
Inherit from jupyter-finalize-object.
(initialize-instance): Cleanup private buffer when client loses scope.
(jupyter-finalize): Remove.

* jupyter-kernel-manager.el (jupyter-kernel-manager):
Inherit from jupyter-finalized-instance.
(jupyter-kernl-manager--cleanup): New function.
(jupyter-finalize, jupyter-kill-kernel-managers): Remove. Update all callers.
(jupyter--kernel-sentinel): Remove MANAGER argument. Update all callers.
(jupyter--start-kernel): Remove MANAGER argument. Update all callers.
(jupyter-start-kernel): Add finalizer to kernel process to cleanup conn-file.

* jupyter-repl.el (jupyter-repl-kill-buffer-query-function):
Remove calls to jupyter-finalize.
2018-11-15 23:02:41 -06:00
Nathaniel Nicandro
ba13ef2419 Move inspection related functions to jupyter-client.el
* jupyter-repl.el (jupyter-inspect, jupyter-inspect-at-point): Do it.

* jupyter-client.el: See above.
2018-11-13 18:17:44 -06:00
Nathaniel Nicandro
a82ae13438 Add jupyter-with-timeout macro
* 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
2018-11-13 17:46:19 -06:00
Nathaniel Nicandro
bbf1d19af3 jupyter-drop-request: Decouple debugging statements from primary method
* jupyter-client.el (jupyter-drop-request):
New :before method that prints debugging statements.
Remove debugging statements from primary method.
2018-11-13 17:46:19 -06:00
Nathaniel Nicandro
82e0e2cda9 jupyter-ioloop-printer 2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
f18c3dfcc6 jupyter-finalize: Kill process if necessary
If an error happens early, the process won't get killed before we kill the
buffer.

* jupyter-client.el (jupyter-finalize): Do it.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
af32a3352f Promote the execution-state to be a slot of jupyter-kernel-client
* 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.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
9f2c88d252 Refactor callback handling
* 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
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
0221a9571d Light refactoring
* jupyter-client.el (jupyter-wait-until): Let `with-timeout` handle errors.
(jupyter--run-handler-maybe, jupyter-add-callback):
(jupyter-kernel-info): Readability.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
8a6aa9baf5 Refactor client channel methods
* 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.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
6c16d184b3 jupyter-handle-message: Let bind `jupyter-current-client' when handling messages
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.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
12085afa96 Add jupyter-channel-ioloop
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.
2018-11-13 17:46:07 -06:00
Nathaniel Nicandro
6942a20e8a Add new jupyter-ioloop implementation
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`
2018-11-13 17:46:03 -06:00
Nathaniel Nicandro
005664a381 Decouple debugging statements from implementation
* jupyter-client.el (jupyter-send): Add new :before method that prints
debugging statements, remove debugging statements from primary method.
2018-11-08 21:33:26 -06:00
Nathaniel Nicandro
348541dfe7 Update documentation and commentary 2018-11-08 21:30:32 -06:00
Nathaniel Nicandro
5b65eb4f24 Move jupyter--debug to jupyter-base.el from jupyter-client.el
This is so that other parts of Jupyter can use it to emit debug statements.
2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
2642450e82 jupyter-client.el: Add jupyter-verify-inhibited-handlers
* jupyter-client.el: Add the new function
(jupyter-send): Use it
2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
2ae8c6a7c1 Associate pending requests with a client
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.
2018-11-08 21:21:23 -06:00
Nathaniel Nicandro
22796ad4cd jupyter-client.el: Add jupyter-clients
* jupyter-client.el: Add the function

* jupyter-repl.el (jupyter-repl-available-repl-buffers): Use it. Ensure REPL
buffers are still live.
2018-11-08 21:15:22 -06:00
Nathaniel Nicandro
0a1ffa66a0 jupyter--ioloop: Complain if ZMQ does not have draft API 2018-11-05 00:00:11 -06:00
Nathaniel Nicandro
05bbe0414d Rename jupyter-startup-timeout to jupyter-long-timeout 2018-11-05 00:00:08 -06:00
Nathaniel Nicandro
57f262c2e3 Implement option to show a progress reporting message in jupyter-wait-until* functions 2018-11-01 19:20:25 -05:00
Nathaniel Nicandro
2f3f910598 Replace deprecated destructor method with jupyter-finalizer 2018-10-25 23:59:47 -05:00
Nathaniel Nicandro
4c710ed235 jupyter-load-language-support: Fix assertion 2018-10-25 23:59:47 -05:00
Nathaniel Nicandro
8896e88476 Move language support definitions to their own files
* Define `jupyter-load-language-support` which takes a client and loads the
  language support definitions of the client's kernel language.

* Call `jupyter-load-language-support` when initializing a REPL buffer in
  `jupyter-repl-mode`. Note this also takes care of loading the kernel support
  for a `jupyter-org-client' since a REPL buffer is setup before evaluating any
  `org-mode` source code blocks.

* Move language specific methods to their own files named `jupyter-LANGUAGE.el`
2018-10-25 23:59:46 -05:00
Nathaniel Nicandro
ecd6a3098b Move jupyter-eval from jupyter-repl.el to jupyter-client.el 2018-10-25 23:17:28 -05:00
Nathaniel Nicandro
67a3f997bd Allow jupyter-inhibit-handlers to be inverted
That is, give a way to only run handlers for the message types in the list
instead of inhibiting them.
2018-10-25 23:17:28 -05:00
Nathaniel Nicandro
842c920760 Be more robust when checking the jupyter-lang method specializer 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
56477b2eae jupyter-client.el: Add jupyter-startup-timeout 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
288fb17ece Update comments 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
673747dc03 Add kill-emacs-hook functions for cleaning up clients and managers
If `kill-emacs` is called while the kernel process or client channel processes
are still alive, the process sentinels do not run and thus the cleanup of the
clients and managers does not happen. Thus we need to explicitly do this
cleanup when `kill-emacs` is called.
2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
c3690eb2ea Use accept-process-output 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
a7023078cc jupyter-code-context: Update documentation 2018-10-25 23:17:27 -05:00
Nathaniel Nicandro
7d824f4915 Add new :input-request message type
This replaces the behavior of the `:input-reply` message
type. A kernel sends an `:input-request` to the frontend
and the client sends an `:input-reply`.
2018-10-25 23:17:26 -05:00
Nathaniel Nicandro
84fce2cd08 Silence byte compiler about undefined variables 2018-10-25 23:17:26 -05:00
Nathaniel Nicandro
2841753bad Consider the active region when obtaining the jupyter-code-context 2018-10-25 23:17:26 -05:00
Nathaniel Nicandro
6ab44867d1 Fix code position in jupyter-line-context
The cursor position is 1 relative, I think. At least this
gives the right results using the Julia kernel.
2018-10-25 23:17:26 -05:00
Nathaniel Nicandro
5f091d972a Remove unused dependency 2018-10-25 23:17:26 -05:00
Nathaniel Nicandro
39382227e7 Take into account newer versions of zmq 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
a9246fcecb Rename with-jupyter-* to jupyter-with
Ensure that all functions and macros have the same
pseudo-namespace
2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
34e52de1d4 Simplify inspect requests
* Rename `jupyter-repl-inspect-at-point` -> `jupyter-inspect-at-point`

* Refactor inspection
2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
1198965d57 Documentation changes 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
ac812a8599 Add a custom method generalizer for a kernel language 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
14ef40acd4 Reduce priority of jupyter-land method context 2018-10-25 23:17:25 -05:00
Nathaniel Nicandro
19abd9a5c6 Define and use the jupyter-lang method context specializer
* Define the `jupyter-lang` method context specializer that
  specializes against the kernel language of
  `jupyter-current-client`

* Remove the kernel support API

* Replace the kernel support API with methods that can be
  specialized using the `jupyter-lang` context specializer.
2018-10-25 23:17:09 -05:00
Nathaniel Nicandro
2492ce3143 Use buffer-substring-no-properties to avoid copying properties 2018-10-25 23:07:46 -05:00
Nathaniel Nicandro
a8231db79b Rename jupyter-repl-current-client to jupyter-current-client
Also move `jupyter-current-client` to `jupyter-client.el`
2018-10-25 23:07:46 -05:00
Nathaniel Nicandro
8bb43e6c68 Rename jupyter-repl-language to jupyter-kernel-language
Also move `jupyter-kernel-language` to `jupyter-client.el`
2018-10-25 23:07:46 -05:00
Nathaniel Nicandro
34aaaf2a66 Update documentation of jupyter-start-channels 2018-10-25 22:57:33 -05:00