Commit graph

1834 commits

Author SHA1 Message Date
Nathaniel Nicandro
42002e3ac3 Let buffer change functions handle continuation prompts 2017-12-27 21:23:40 -06:00
Nathaniel Nicandro
bd92ce16bb Use indent-line-function instead of binding TAB 2017-12-27 21:21:33 -06:00
Nathaniel Nicandro
8603c0226e Implement buffer change functions
- After a buffer change, check to see if a continuation prompt needs to be
  inserted

- Before a buffer change, check to see if a continuation prompt needs to be
  removed
2017-12-27 21:17:46 -06:00
Nathaniel Nicandro
d21c7a2bed Clean up REPL buffer initialization 2017-12-27 21:15:59 -06:00
Nathaniel Nicandro
3071b64611 Clean up how text is inserted in REPL buffer 2017-12-27 21:13:23 -06:00
Nathaniel Nicandro
c3c3f7c44e No underscores 2017-12-27 21:07:36 -06:00
Nathaniel Nicandro
e9e35cb177 Remove comments 2017-12-27 00:34:19 -06:00
Nathaniel Nicandro
06fee9c57a Properly initialize kernel client with a kernel manager 2017-12-27 00:32:55 -06:00
Nathaniel Nicandro
363f59ef76 Remove time decoding from main loop in client subprocess 2017-12-27 00:32:00 -06:00
Nathaniel Nicandro
59a2a468a7 Only use control channel in kernel manager 2017-12-27 00:30:47 -06:00
Nathaniel Nicandro
a1fc86af0a Properly initialize kernel manager instances 2017-12-27 00:26:12 -06:00
Nathaniel Nicandro
33dd60942e Cleanup kernel manager 2017-12-27 00:21:20 -06:00
Nathaniel Nicandro
72fc893164 Return nil when prefix is nil in jupyter-find-kernelspec 2017-12-27 00:18:34 -06:00
Nathaniel Nicandro
a93204341a Add some defaults to a history request 2017-12-27 00:18:00 -06:00
Nathaniel Nicandro
714b23c12f Guard against empty messages when flags are used 2017-12-27 00:17:03 -06:00
Nathaniel Nicandro
6721f91b08 Only attempt to decode time when a date field exists 2017-12-27 00:16:11 -06:00
Nathaniel Nicandro
785c8242d8 Fix time decoding 2017-12-27 00:13:43 -06:00
Nathaniel Nicandro
f6a3690c59 Add some debug statements 2017-12-27 00:12:39 -06:00
Nathaniel Nicandro
d28dc7a3af Add a sentinel to the client's ioloop 2017-12-27 00:00:59 -06:00
Nathaniel Nicandro
c377529d73 [WIP] A working REPL 2017-12-23 15:34:28 -06:00
Nathaniel Nicandro
46a449c496 Raise error when connecting channel with an unknown channel type 2017-12-22 00:54:18 -06:00
Nathaniel Nicandro
c6445530c7 HB channel process ignores signals 2017-12-22 00:53:18 -06:00
Nathaniel Nicandro
5b2afb3ea0 [WIP] Kernel manager 2017-12-22 00:50:56 -06:00
Nathaniel Nicandro
2616f5d49b Decode datetime into time objects, add more convenience functions 2017-12-22 00:38:03 -06:00
Nathaniel Nicandro
6c6ad568d6 Use lexical-let when needed 2017-12-22 00:36:49 -06:00
Nathaniel Nicandro
b82665f889 Collect messages from kernel before sending to parent process
Instead of directly sending every received message to the parent emacs process
at the moment we receive it. The messages are stored in a queue. Only when we
do not receive a message from the kernel for two polling periods or when the
queue is full will the messages be sent to the parent process. When the
messages are sent, they are first sorted by their timestamp and prioritized
based on channel.
2017-12-21 18:20:35 -06:00
Nathaniel Nicandro
e0b5da2580 Just silently drop messages received that were not requested by us 2017-12-21 18:13:49 -06:00
Nathaniel Nicandro
5f5a742d3d Slots for a jupyter-kernel-client are always bound 2017-12-21 18:12:25 -06:00
Nathaniel Nicandro
72ab6b1d9e JSON encoded plists convert nil to {} 2017-12-21 18:10:19 -06:00
Nathaniel Nicandro
0f44d88874 Add fractional seconds in timestamp 2017-12-21 18:09:45 -06:00
Nathaniel Nicandro
df193db165 Remove message-callbacks 2017-12-19 21:54:11 -06:00
Nathaniel Nicandro
1848cc256a Properly cleanup ioloop subprocess
Also wrap loops that wait for subprocess output with timeouts
2017-12-19 18:47:57 -06:00
Nathaniel Nicandro
94636454c0 Use accept-process-output when waiting 2017-12-19 18:16:58 -06:00
Nathaniel Nicandro
fb8c13055d Add test for sending the various message types 2017-12-19 18:15:51 -06:00
Nathaniel Nicandro
cd158b2de6 Fix indentation 2017-12-19 18:13:42 -06:00
Nathaniel Nicandro
0f84618914 Introduce jupyter-request and jupyter-callback types
`jupyter-request` encapsulates a request ID, request callbacks, and a flag
variable which tells you if the kernel has sent an idle message for this
request.

`jupyter-callback` encapsulates a callback function and a flag variable
determining if the callback has run at least once. The `callbacks` field of a
`jupyter-request` is an alist mapping reply types to `jupyter-callback`
objects.

Whenever a message is sent to the kernel a new `jupyter-request` object is
created and returned from one of the `jupyter-request-*` methods. This object
holds all the required information to track a message that the kernel is
handling. When a message is received from the kernel, the client checks its
`requests` hash table for the `jupyter-request` object associated with the
message and runs any callbacks for the message and updates the flag variables
of the request and callback if necessary.

The request is considered complete and removed from the `requests` hash table
when an idle message has been received for the request and all callbacks have
run at least once. Note that this is almost surely does not handle all cases
since there may be situations where you would like a callback to run multiple
times while an idle message has already been sent.
2017-12-19 18:13:16 -06:00
Nathaniel Nicandro
3b7b6efaaa Take into account the status field of an is_complete_reply 2017-12-19 11:55:07 -06:00
Nathaniel Nicandro
a52ab008ed Properly handle shutdown messages 2017-12-19 11:54:10 -06:00
Nathaniel Nicandro
09aa179636 Implement starting/stopping channels in ioloop subprocess 2017-12-19 11:50:50 -06:00
Nathaniel Nicandro
e9f04b20f8 Make the hb channel more efficient
Instead of constantly sending the subprocess input on every polling loop, poll
for input on stdin using the poller.
2017-12-19 11:47:45 -06:00
Nathaniel Nicandro
29cd9912f0 Fix typo 2017-12-17 02:58:11 -06:00
Nathaniel Nicandro
c04998677c Implement callback which fires for all messages associated with a request
If `t` is passed as the `MSG-TYPE` argument of `jupyter-add-receive-callback`,
then it signifies that the associated callback will run for every message that
is received in response to a request.
2017-12-17 02:53:31 -06:00
Nathaniel Nicandro
1e246ee480 [WIP] Move all socket communication to a subprocess
With this new implementation, all communication between the kernel and the
client happens in a subprocess. When the client would like to send a message,
the parent emacs process generates the required plist and sends it to the
subprocess for encoding and sending to the kernel. When a message is received,
the subprocess decodes it and prints it to the pipe for the parent emacs
process to read.

This implementation also introduces the use of futures to avoid having to wait
for subprocess output when sending a message to the kernel. Every
`jupyter-request-*` function now returns a primitive future object which is
just a cons cell with the `car` equal to `:jupyter-future`. When the `cdr` of
the future is non-nil, then it is the message ID of the sent request. This acts
as a check to ensure that the message ID is available from the future object,
if the `cdr` is nil the ID is not available, but if the `cdr` is non-nil then
it is the message ID. The convenience function `jupyter-ensure-id` ensures that
the message ID is available and returns the ID.

The future acts as a stand in for the message ID of the encoded request which
will be retrieved from the subprocess once the message has been encoded and
sent to the kernel. This future object is meant to be passed to
`jupyter-add-receive-callback` and other related functions the same way as an
actual message id.
2017-12-17 02:53:15 -06:00
Nathaniel Nicandro
805255e816 New function jupyter-connect-channel
This function returns a socket based on a channel type and endpoint. The
channel type is mapped to the required socket type based on
`jupyter-channel-socket-types`. This is a convenience function to avoid having
to use `jupyter-channel-socket-types` directly.
2017-12-17 02:32:28 -06:00
Nathaniel Nicandro
f5afa2ef07 Minor style and documentation changes 2017-12-16 19:02:11 -06:00
Nathaniel Nicandro
3d2aa1fe9e Update tests 2017-12-16 19:01:09 -06:00
Nathaniel Nicandro
80de6579fa Stick to using timers instead of a polling subprocess
I believe I was misunderstanding the use of `zmq-poll` on the file descriptors
in a subprocess. It seems that polling the file descriptors doesn't seem to
work.

Currently I am sticking to running periodic timers in emacs itself to process
messages. This may slow down emacs when connecting to lots of clients that are
receiving and sending lots of messages.

What I would like to move towards is having a subprocess which connects to the
required endpoints and listens for incoming messages. When a message arrives,
it decodes it and sends it back to the parent emacs process. When I would like
to send a message, I just send the raw plist to the subprocess and it encodes
and sends it through the socket. So the subprocess will take care of
encoding/decoding messages and sending/receiving messages on sockets. Whereas
the parent emacs process will send/receive plists.
2017-12-16 18:54:40 -06:00
Nathaniel Nicandro
4f1e466754 Remove unnecessary lexical-let 2017-12-15 22:40:31 -06:00
Nathaniel Nicandro
76de6a8b4a Ensure kernel connection file is finished writing before reading from it 2017-12-15 22:37:59 -06:00
Nathaniel Nicandro
ab2931beb6 Remove comment
The problem appears to be that I was not waiting until the kernel was finished
handshaking with the `jupyter console` application. Kernels are currently
started using the `jupyter console` command which was causing messages not to
be received by `jupyter-kernel-client`
2017-12-15 22:34:17 -06:00